Home Products Tips VBA OfficeOne on Windows Links

List macros in a presentation

The ListMacrosInPresentation() routine takes an Presentation object and a Collection object as input. In the Collection object, it returns the macros that are within the presentation.

Microsoft Visual Basic for Applications Extensibility needs to be included in the set of references. To add a reference to it

  1. Select Tools | References....
  2. Select Microsoft Visual Basic for Applications Extensibility from the available references.
  3. Click OK.

Function GetProcedureFromLine(ByVal CM As CodeModule, _
    ByRef StartLine As Long) As String

    Dim I As Long
    Dim S As String

    I = StartLine
    Do While I < CM.CountOfLines
        S = CM.ProcOfLine(I, vbext_pk_Proc)
        If S <> "" Then
            Exit Do
        End If

        I = I + 1
    Loop

    If S <> "" Then
        StartLine = I
        GetProcedureFromLine = S
    End If
End Function

Sub ListMacrosInPresentation(ByVal Pres As Presentation, _
    ByVal C As Collection)

    Dim I As Long
    Dim StartLine As Long
    Dim ProcName As String

    With Pres.VBProject
        For I = 1 To .VBComponents.Count
            With .VBComponents(I)
                StartLine = .CodeModule.CountOfDeclarationLines + 1
                Do While StartLine < .CodeModule.CountOfLines
                    ProcName = GetProcedureFromLine(.CodeModule, _
                        StartLine)
                    If ProcName = "" Then
                        Exit Do
                    End If

                    C.Add ProcName
                    StartLine = .CodeModule.ProcCountLines(ProcName, _
                        vbext_pk_Proc) + StartLine
                Loop
            End With
        Next
    End With
End Sub

Sub Demo()
    Dim C As New Collection
    Dim I As Long
    Dim S As String

    S = ""
    ListMacrosInPresentation ActivePresentation, C
    For I = 1 To C.Count
        S = S + C(I) + ", "
    Next
    MsgBox Left(S, Len(S) - 2)
End Sub


Home | Products | Tips | VBA | Windows | Links

Contact OfficeOne on email at officeone@officeonemac.com. Copyright © 2001-2013 OfficeOne. All rights reserved.

page counter