VBA – Class/Procedure names

0 pts.
Tags:
VB.NET
VBA
Visual Basic
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
ASKED: October 21, 2004  7:35 AM
UPDATED: October 27, 2004  4:29 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Darryn
    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 pointsBadges:
    report
  • Mattaux
    Thanks for the info. However, the code is not written behind a Spreadsheet but is instead compiled into a dll. Matt
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following