0 pts.
 VBA – Class/Procedure names
Hi, Does anyone know how to grab the name of a Class Module (or Procedure) at run-time without having to hard-code it? Many thanks Matt

Software/Hardware used:
ASKED: October 21, 2004  7:35 AM
UPDATED: October 27, 2004  4:29 AM

Answer Wiki:
Have you tried getting the name from the object that contains the class or procedure? For example if the procedure is in say sheet1 of an excel workbook, you could get the name by drilling down in the sheet1 object. Hope that helps get you going in a positive direction.
Last Wiki Answer Submitted:  October 21, 2004  11:13 am  by  Jnbutler   0 pts.
All Answer Wiki Contributors:  Jnbutler   0 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Not quite sure what you are trying to accomplish here, but this script will loop through all of the VBE Objects in your workbook project, and then reads in the name of the module if it has any code in it.

Sub countModules()

Dim modCount As Integer
Dim modName As String
Dim codeCount As Integer

modCount = ThisWorkbook.VBProject.VBComponents.Count
For a = 1 To modCount

codeCount = ThisWorkbook.VBProject.VBComponents(a).CodeModule.CountOfLines
If codeCount > 0 Then
modName = ThisWorkbook.VBProject.VBComponents(a).Name
End If

Next a

End Sub

If you need to know more about the modules, you should use the CodeModule object (you need to install the VBA add-in Object Model), which allows you to modify code dynamically.

If you just want to get the name of the module/object that is active, use the SelectedVBComponent property.

Darryn

 765 pts.

 

Thanks for the info. However, the code is not written behind a Spreadsheet but is instead compiled into a dll.

Matt

 0 pts.