none
Scope of a VB Component RRS feed

  • Question

  • Hi,

    Is there a way to get the scope of procedure or function?

             For Each objVbComp In objVbProj.VBComponents
    
                ' Find the code module for the project.
                Set objVbMod = objVbComp.CodeModule
    
                ' Scan through the code module, looking for procedures.
                intLine = 1
                Do While intLine < objVbMod.CountOfLines
                   strProcName = objVbMod.ProcOfLine(intLine, enmProcKind)

    The code above returns f.i. "Workbook_AddinInstall"

    Now I would like to know the declaration scope: Private Sub, Public Sub or just Sub?

    Is there a way to get this info?

    Sunday, October 7, 2018 1:59 PM

Answers

  • See if you can use the following as starting point:

    Sub Test()
        Dim objVbProj As VBProject
        Dim objVbComp As VBComponent
        Dim objVbMod As CodeModule
        Dim intLine As Long
        Dim strProcName As String
        Dim strPrevName As String
        Dim strLine As String
        Dim strDescription As String
        Set objVbProj = ActiveWorkbook.VBProject
        For Each objVbComp In objVbProj.VBComponents
            ' Find the code module for the project.
            Set objVbMod = objVbComp.CodeModule
            ' Scan through the code module, looking for procedures.
            intLine = 1
            Do While intLine < objVbMod.CountOfLines
                strProcName = objVbMod.ProcOfLine(intLine, vbext_pk_Proc)
                If strProcName <> strPrevName And strProcName <> "" Then
                    strLine = objVbMod.Lines(intLine, 1)
                    Do While strLine = ""
                        intLine = intLine + 1
                        strLine = objVbMod.Lines(intLine, 1)
                    Loop
                    strDescription = Left(strLine, InStr(strLine, strProcName) - 2)
                    Debug.Print strDescription, strProcName
                    strPrevName = strProcName
                End If
                intLine = intLine + 1
            Loop
         Next objVbComp
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by JP Ronse Sunday, October 7, 2018 2:46 PM
    Sunday, October 7, 2018 2:16 PM

All replies

  • See if you can use the following as starting point:

    Sub Test()
        Dim objVbProj As VBProject
        Dim objVbComp As VBComponent
        Dim objVbMod As CodeModule
        Dim intLine As Long
        Dim strProcName As String
        Dim strPrevName As String
        Dim strLine As String
        Dim strDescription As String
        Set objVbProj = ActiveWorkbook.VBProject
        For Each objVbComp In objVbProj.VBComponents
            ' Find the code module for the project.
            Set objVbMod = objVbComp.CodeModule
            ' Scan through the code module, looking for procedures.
            intLine = 1
            Do While intLine < objVbMod.CountOfLines
                strProcName = objVbMod.ProcOfLine(intLine, vbext_pk_Proc)
                If strProcName <> strPrevName And strProcName <> "" Then
                    strLine = objVbMod.Lines(intLine, 1)
                    Do While strLine = ""
                        intLine = intLine + 1
                        strLine = objVbMod.Lines(intLine, 1)
                    Loop
                    strDescription = Left(strLine, InStr(strLine, strProcName) - 2)
                    Debug.Print strDescription, strProcName
                    strPrevName = strProcName
                End If
                intLine = intLine + 1
            Loop
         Next objVbComp
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by JP Ronse Sunday, October 7, 2018 2:46 PM
    Sunday, October 7, 2018 2:16 PM
  • Hi Hans,

    Thank you, I need to tweak it a bit to exclude comments/headers (MZTools you know) but I can handle this.

    I was already playing with this approach but was still hoping that there was also a direct way iso of looping. It will take extra time to finish, so be it.

    Greetings from Belgium.

    JP Ronse


    • Edited by JP Ronse Sunday, October 7, 2018 2:51 PM
    Sunday, October 7, 2018 2:45 PM