nitt1995
06-19-2006, 12:54 PM
My VBA project imports in *.bas files into a workbook and I need a way to check to see that functions with the same name don't already exist. I plan to name the modules when they are imported (preferably to the same file name), and just search for the same module name. I will then give the user the choice to replace the file.
I have not yet found out how to name an imported module. It always takes the next in the sequence Module1, Module2..... ModuleX.
I have figured out this code to search for all components, including modules. I don't know how the module1 is selected without knowing what the name is?
Therefore, I don't know how to name the module, without already knowing its current name. (how do you name it during creation?).
Is there a way to "pick-off" the modules from the worksheets, class modules, etc?
Thanks!
Private Function listComponents()
Dim ref As Object
Dim msg As String
msg = ""
For Each ref In ActiveWorkbook.VBProject.VBComponents
msg = msg & ref.Name & vbCrLf
If (ref.Name = "Module1") Then
'Renames module, once selected.
ref.Name = "Module2"
End If
Next ref
MsgBox msg
'deletes module that you know the name
With ActiveWorkbook.VBProject.VBComponents
.Remove ActiveWorkbook.VBProject.VBComponents("why")
End With
End Function
While on the same subject, is there a way to isolate all of the functions listed on a given module? Can I do a similar listFunction sub to list all of the subs and functions on a given module?
I have not yet found out how to name an imported module. It always takes the next in the sequence Module1, Module2..... ModuleX.
I have figured out this code to search for all components, including modules. I don't know how the module1 is selected without knowing what the name is?
Therefore, I don't know how to name the module, without already knowing its current name. (how do you name it during creation?).
Is there a way to "pick-off" the modules from the worksheets, class modules, etc?
Thanks!
Private Function listComponents()
Dim ref As Object
Dim msg As String
msg = ""
For Each ref In ActiveWorkbook.VBProject.VBComponents
msg = msg & ref.Name & vbCrLf
If (ref.Name = "Module1") Then
'Renames module, once selected.
ref.Name = "Module2"
End If
Next ref
MsgBox msg
'deletes module that you know the name
With ActiveWorkbook.VBProject.VBComponents
.Remove ActiveWorkbook.VBProject.VBComponents("why")
End With
End Function
While on the same subject, is there a way to isolate all of the functions listed on a given module? Can I do a similar listFunction sub to list all of the subs and functions on a given module?