Check module name via VBA

Asked

Viewed 328 times

3

Hello, I need to check the name of a module to change it later.

The name of the module changes a lot, depending on each document,and not to run all possible names, because it would take too long.

For this I need a code that reads the module names in my VBA project.

What I’ve accomplished so far is this:

Sub Mudar_cód()

    ObjVbProj = Workbooks(ActiveWorkbook.Name).VBProject.VBComponents("MFPC0000").CodeModule

    If ObjVbProj = "MFPC0000" Then

        MsgBox "SIM"

    End If

End Sub

1 answer

3


See if the function below helps you, as it lists all modules per spreadsheet:

Sub BuscaModulos()
Dim modName As String
Dim wb As Workbook
Dim l As Long

 Set wb = ThisWorkbook

For l = 1 To wb.VBProject.VBComponents.Count
    With wb.VBProject.VBComponents(l)
        modName = modName & vbCr & .Name
    End With
Next

 MsgBox "Resultado:" & vbCr & modName
 Set wb = Nothing

End Sub
  • Perfect! I’ll just fit the code into my code, but that was it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.