Verify module name via VBA

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 can not run all possible names, as it would take a long time.

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

What I accomplished so far was this:

Sub Mudar_cód()

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

    If ObjVbProj = "MFPC0000" Then

        MsgBox "SIM"

    End If

End Sub
    
asked by anonymous 12.06.2017 / 16:10

1 answer

3

See if the function below helps you by listing all the modules per worksheet:

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
    
12.06.2017 / 18:24