Question

I have about 25 PowerPoint presentations, each with at least 45 slides. On each slide is a question with four possible answers and a help button which provides a hint relevant to the question. Each of the answers and the help button is a PowerPoint Action button that launches a macro.

I am attempting to migrate all the questions/answers/hints into a SQL Database. I've worked with Office.Interop before when working with Excel and Word and I have plenty of SQL DB experience, so I don't foresee any issues with actually extracting the text portion of the question and answer and putting it into the db.

What I have no idea how to do is given an object on a slide -> get the action button info -> Get the macro name -> and finally get the macro's vb code. From there I can figure out how to parse out which is the correct answer and what the text of the hint is.

Any help/ideas would be greatly appreciated.

Was it helpful?

Solution

To get the name of your items Run Macro settings, you'll run something like this:

Sub ActionSettingName()
    Dim p As Presentation
    Set p = ActivePresentation
    Dim s As Slide
    Dim sh As Shape
    Dim macroName As String
    For Each s In p.Slides
        For Each sh In s.Shapes
            If sh.Type = msoGroup Then
                Dim gs As Shape
                For Each gs In sh.GroupItems
                    PrintMacroName gs
                Next
            Else
                PrintMacroName sh
            End If
        Next
    Next
End Sub
Sub PrintMacroName(sh As Shape)
    If sh.ActionSettings(ppMouseClick).Action = ppActionRunMacro Then
        macroName = sh.ActionSettings(ppMouseClick).Run
        Debug.Print macroName
    End If
End Sub

UPDATE: To get ActionSettings for TextRanges, please find below:

Sub ActionSettingName()
    Dim p As Presentation
    Set p = ActivePresentation
    Dim s As Slide
    Dim sh As Shape
    For Each s In p.Slides
        For Each sh In s.Shapes
            Dim tr As TextRange
            Set tr = sh.TextFrame.TextRange
            Dim macroName As String
            For i = 1 To tr.Runs.Count
                macroName = tr.Runs(i).ActionSettings(ppMouseClick).Run
                If Len(macroName) > 0 Then
                    Dim runText As String
                    runText = tr.Runs(i).Text
                    Debug.Print "RUN: " & runText & vbCrLf & "MACRO: " & macroName
                End If
            Next
        Next
    Next
End Sub

Then you'll want to search for and extract that macro (and anything else you need) from the VBE inside the last For/Next loop.

There are a few references on SO on how to extract all macros in Excel/Word and work with the VBProject model - the techniques are identical to PowerPoint. See Programmatically extract macro (VBA) code from Word 2007 docs for one of the better examples. A much more comprehensive intro to the VBProject object model exists at Programming The VBA Editor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top