SHOW ALL CODE MODULES & SUBS IN A WORKBOOK
Jun 8, 2007
A recent message prompted me to complete a project to show all modules and subroutines in a workbook.
As use of VBA to manipulate the VB Editor is a recurring issue I thought it a good idea to share this.
Option Base 1
Dim WBname As String
Dim ws As Worksheet
Dim TitleStr As Variant
Dim VBProject As Object
Dim ToRow As Long
Dim ToCol As Integer
Dim ComponentType
Dim MyComponent As Object
Dim ComponentName As String
Dim TypeArray As Variant
Dim StdCol As Integer
Dim LastLine As Long
Dim CurrentLineNumber As Long
Dim CurrentLineText As String
Sub SHOW_ALL_MODULES()
WBname = ActiveWorkbook.FullName
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets("WB Contents")
If Err.Number 0 Then ' sheet not exist....................
View 2 Replies
ADVERTISEMENT
Mar 7, 2012
I have the following code in a module that I would like to initiate when the workbook opens:
Code:
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" ( _
ByVal lpBuffer As String, _
ByRef nSize As Long) As Long
Public Property Get ComputerName() As String
[Code] ........
In a worksheet, I have =compname() in cell A1 and =hdserialnumber() in A2. What is the trick to make the values in these cells appear as soon as the worksheet opens?
View 2 Replies
View Related
Jul 11, 2007
This is the code after editing to make it more clear
Public Sub 1()
BookA= activeworkbook. name
BookB=Application.Workbooks.Add
Workbook(BookB).activate
End Sub
Public Sub 2()
BookB=Activeworkbook.name
With BookB. sheets(1)
.range("A1")=BookA.sheets(1).range("B1")
End Sub()
At the end of public sub 1, BookB is the active workbook. What I want to do in public sub 2 is to copy some data from BookA to BookB. Unfortunately, when moving from public sub 1 to public sub 2, BookA needs to be defined again. The code above is the code that I use in my add-ins. I figured out for non add-ins code I can define BookA with thisworkbook.name when BookB is active as I before work with BookA. This does not apply for add-ins as thisworkbook will refer to my add-ins code. Is there anyway of keeping definition of BookA is constant from one public sub to another public sub? This is simplified code. In fact, I can't merge public sub 2 with public sub 1 due to some reason which I don't say it here.
View 6 Replies
View Related
May 18, 2009
I would like to protect the VBA modules I have written in a spreadsheet. Is there any way of password protecting these (as there is with Excel workbooks/worksheets) -such that users can not see the VBA code unless they enter a password?
View 4 Replies
View Related
Jun 24, 2014
Sometimes I will copy a macro to a different workbook and then modify it to do what I want instead of writing it new.
If it has a reference to a different macro, I have to go through each module in the "VBA Project" to fine it and see what it does.
I was wondering is there a way to fine a sub routine in a project without scrolling through each module to fine it? (without going back to the workbook and clicking on the view macro button)
Also is there a way to alphabetize each sub routine in a module so it can be found easier
I've started to group my subs better so I can find them easier, but there are a lot of old ones.
I just learned that I can name each module.
View 5 Replies
View Related
Sep 17, 2007
I am basically after a script that can be run from a persons workbook via an Excel Addin, e.g. they click an "Update" button, and the script imports the Forms and Modules from another workbook that i specify.
I do not however want the data held on the spreadsheet to change, just the Modules & Forms in the VBA project.
View 6 Replies
View Related
May 17, 2008
I cannot figure out how to get my error handler to work, or actually, not work. It seems to work fine when there is an error, but the code still gets read even when there was not an error. Basically, I am trying to open a file, which may or may not be there. When it is not there I want a message to pop up informing the user. However, when the file is there and it opens, the error handler still gives the message box. Any ideas what I am doing wrong?
Private Sub btnOK_Click()
Application. ScreenUpdating = False
Dim LCSfile As String
LCSfile = frmSelectFile.Listbox1.Value
On Error Goto ErrHandler
Workbooks.Open Filename:=sPath & sDate & "" & LCSfile & "QUANT.CSV"
ErrHandler:
MsgBox ("File is not quantitated. Please select another file.")
Application.ScreenUpdating = True
End Sub
View 2 Replies
View Related
Jul 8, 2009
I am working with a class module and some fields require specific inputs that another coder may not intuitively know. How can I create a list of acceptable conastants that will appear as a drop down when the user is coding with the custom object?
For example:
I am creating an Email Engine object that will handle all my emailing needs in code, because coding emails is such a pain. Then I can just create the blasted thing, import the class module where needed and never have to worry about it again. Some coworkers are interested in using the module for their projects when I am finished. I want to put an option for message flags in the object, but only certain colored flags are allowed. How can I get the VBE to show a little drop down with the acceptable flag constants when another user types
[Object Variable].MessageFlagColor = {drop down list of options}
I started with
Public Property Let MessageFlagColor(Value As Constants)
End Property
But that hasn't gotten me anywhere.
View 9 Replies
View Related
Jan 27, 2009
I use excel 2002 but some of my office are on 97, i want to add a small workbook open event code which works for me but debugs for the others?? The code is basically, go to a tab, on that tab and that range sort..
View 2 Replies
View Related
Aug 1, 2013
My company has files that are already in use. I don't know too many details about how they work, but somehow saving the file will screw it up and my boss has to go back and reset something or other to correct it. Obviously it's connected to some other software somewhere. The code below will block Save and Save-As. BUT how do I get the file to hold onto the code without actually saving the file after the code is added (since the file shouldn't be saved)?
VB:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = False Then
Cancel = True
[Code].....
View 1 Replies
View Related
Mar 21, 2012
I'd like to combine two VBA subs existing on a single sheet. Since they can't duplicate I need some sort of a switch statement...?
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim VRange As Range, cell As Range
Dim Msg As String
Dim ValidateCode As Variant
Set VRange = Range("E4:E100")
For Each cell In Target
[Code]....
View 5 Replies
View Related
May 20, 2014
I have two subs which I've been trying to combine into one. Essentially all that is changing is the slicer name and range value.
Here's what I have:
Code:
Private Sub Workbook_SheetPivotTableChangeSync(ByVal Sh As Object, ByVal Target As PivotTable)
Dim cache As Excel.SlicerCache
Set cache = ActiveWorkbook.SlicerCaches("Slicer_Project_Type3")
Dim sItem As Excel.SlicerItem
Dim myString As String
For Each sItem In cache.SlicerItems
If sItem.Selected = True Then
myString = myString & "," & sItem.Name
[code].....
But it's erroring out on me.
View 4 Replies
View Related
Jun 4, 2009
I have 2 sub, and I want to use the same variables that reference values on my spreadsheet.
for instance, I declare and set ws as worksheet("sheet1") in the first sub.
in the second one, I also want to reference to the same ws. Instead of having to declare it twice, being redundant, what would be a good way to do this?
View 9 Replies
View Related
May 8, 2007
How can I have a sub repeat itself? I have a code and I want it to ask the user at the end if they would like to do it again. If so the whole sub needs to be repeated. I'm sure this has something to do with looping, but I don't know how to manage this.
View 3 Replies
View Related
Jun 25, 2014
I'm trying to find a way to save a single sheet of an excel workbook and in the same process delete all vba code and shapes from the new single sheet workbook. I was looking around and found this code which does save only the single sheet to a new one sheet workbook but doesn't delete the vba and shape that I have used to assign macros to in the original.
Code:
Sub SaveSheetAsNewBook()
Dim wb As Workbook
Dim InitFileName As String
Dim fileSaveName As String
Dim wshape As Shape
InitFileName = ThisWorkbook.Path & Format(Date, "mm.dd.yy")
[code]....
View 2 Replies
View Related
Mar 29, 2007
I am trying to write a code for a dropdown box where only the sheet selected from the dropdown is visible. Then, when you select another option from the dropdown, that sheet is the one visible (and all others are hidden).
View 9 Replies
View Related
Jan 14, 2014
The amazing code I saw was from this thread Auto lock cells after data entry when file saved... where the code was made by Jafaar Tribak.
It basically locks cells that have had data inputted into them when the file is saved (with a nice prompt warning of the used cells being locked.
This is Jafaar's file [URL]
And this is my file where I'm trying to make it work in the "Employee data entry" Sheet:
[URL]
And finally this is the file after I tried to copy the code over : [URL]
Trying to make it so that in the employee data entry sheet locks cells after an employee inputs some data into said cells.
I thought that by setting an "inputrange" on the employee data entry sheet the code would track it down automatically but maybe I'm completely wrong. I cant see anything wrong with it (probably because I"m not that good at vba) but I fear I may have left out something really simple!
I seem to disable my other macros when i try to insert this code in (I have a macro that when you click on a cell a calendar pops up so you can click on a day from the calendar rather than typing out the date)
View 9 Replies
View Related
Sep 12, 2006
How is code or functions kept unique to a workbook? for instance i create a few toolbars that are relevant to "work book 1", however when i open another workbook "2" the toolbars do not function properly or are removed by the opening/closing of the work book, similarly other macros seem to struggle with more than one workbbok open at a time.
View 5 Replies
View Related
Aug 19, 2008
I'm having some trouble getting to grips with using/calling variables and other sub routines.
View 9 Replies
View Related
Jan 26, 2009
I have created a few User Defined Types in a Main subroutine, but when I pass them into another sub the intelisense for the elements doesn't come up. I can type in the elements manually - and it all seems to work okay - but with a lot of types and elements I really want it to save me the effort.
View 2 Replies
View Related
Nov 3, 2009
I think I am confused as to how to declare a variable in one sub and use it as an input into another sub. I have attached some code below that assigns a value to two variables and then calls a sub that uses those values. I am brand new to programming so I guess I am confused how to implement this.
View 3 Replies
View Related
Sep 10, 2012
VBA - Exit all Subs not just current
View 2 Replies
View Related
Oct 30, 2013
I have some code I'm running:
Code:
Sub Main ()
Dim Value1 as integer
Value1=5
Call firstroutine
Call secondroutine
End Sub
[code].....
Somehow I need to pass Value1 & Value2 to secondroutine.
View 5 Replies
View Related
Jul 28, 2007
Calling a Sub from another Sub is quite common, how about a Sub that does nothing else but call all the subs to execute the entire job?
Will the subs run sequentially after one completes, or will there be the likley hood they will bump into each other causing all sorts of chaos.
View 9 Replies
View Related
Jan 12, 2007
How can it be that this works?
Sub AA()
Dim ReportFileName As String
Cells(1, 19).Select
ReportFileName = ActiveCell.Value
ChDir "C:"
Workbooks.Open Filename:=ReportFileName _
End Sub
And this doesn't work?
Sub BB()
Dim ReportFileName As String
Cells(1, 19).Select
ReportFileName = ActiveCell.Value
CC
End Sub
Sub CC()
ChDir "C:"
Workbooks.Open Filename:=ReportFileName _
End Sub
Somehow it seems that the value of the string "ReportFileName" is forgotten when running the subroutine CC. How do I make it not "forget" the file name?
View 4 Replies
View Related
Jan 25, 2007
The below is a selection of some of the code i have written to organise data. The below works, but i'm not sure how/if I can make all the subs work in order automatically once I start the first Sub? I realise what I have written is probably pretty poor code so many need changed?
Sub move_to_all()
Sheets("All").Select
Cells.Select
Range("A10").Activate
Selection.Copy
Sheets("Rest").Select
Range("A1").Select
ActiveSheet.Paste
End Sub
Sub Omni_Trades().....................
View 2 Replies
View Related
May 2, 2007
I have Three questions about debugging VBA code of an excel add-in.
-Breakpoints set in certain Public Subroutines are NOT hit. I have an application that writes data to the add-in. You cannot debug the app + the add-in. The add does things(e.g. writes data), then calls a main public macro in the add-in, then the addin takes over. If I comment out the main macro, the parent app halts, then I try to set breaks in the add-in.
After resumeing, some breaks are never hit. I know this because if I set a stack trace (output ing the func name to a temporary worksheet), I see these functions being hit. All the modules are public.
Usually in C, breakpoints are not hit because that code is NOT part of the address space of the program.
2. Very naive question (I am a C,C++ programmer)...some tiimes when I hit F5, the whole app runs, other times a list of macros comes up (just as if I had gone to the menu and went toolsmacros. Why is this?????.....placement of the cursor?????
3. If in the app I have 5 code modules, with two public subroutines each.
HOW COME, IF I GO TOOLSMACROSRUN (same as what I get sometimes when I go F5), I ONLY GET A PARTIAL LISTING OF THE SUBROUTINES, ie NOT ALL 10?
View 3 Replies
View Related
Jul 11, 2007
I am still learning and was wondering what is wrong with this. I have cut some of the code out as it pretty long. This is my main procedure:
Public Sub cal_parameters_Click()
'istat(i) = 0 bonded
' = 1 slip
' = 2 soil yielded
Dim istat(1 To 999) As Single
Call secondary_loop 'calls subprocedure secondary_loop
End Sub
It then calls secondary_loop:................
View 6 Replies
View Related
Feb 19, 2008
is there any way to show the Workbook name in a cell?
i can get it to show using the Footer but i would like it to show in a cell.
ie.
book1.xls
View 9 Replies
View Related
May 31, 2008
I have 10 Workbooks open, one primary workbook where the macro resides, and 9 other, randomly named files (workbooks). The macro needs to copy the values from Workbook2,Sheet1, Range("A1") and paste them into the primary file (location irrelevant for now), close Workbook2, then do the same thing for the remaining open workbooks. Is there a "next" workbook function that doesn't need the "name" of the next workbook?
View 2 Replies
View Related