'PowerPoint VBA - unable to set hyperlink on shape in PPT from Excel code - but the same code works fine from PPT directly

I'm trying to set a hyperlink to a box in PowerPoint from Excel.

If I run this code from PowerPoint, this works fine:

Sub LinkTestInPPT()
    Dim act As Object 'act = Active Presentation
    Dim pptApp As Object
    Set pptApp = GetObject(, "Powerpoint.Application")
    Set act = pptApp.ActivePresentation
    With act.Slides(1).Shapes("LinkedBox").ActionSettings(ppMouseClick)
        .Action = ppActionHyperlink
        .Hyperlink.Address = "http://www.microsoft.com"
    End With
End Sub

If I try to run the same code from Excel - I can get the contents of the same box, so I know the object reference is correct, but I get a runtime error that says "Automation error" when trying to apply action settings from Excel to PowerPoint. Here's the code that DOESN'T work (after the message box) when run from Excel.

Sub LinkTestFromExcelToPPT()
    Dim act As Object 'act = Active Presentation
    Dim pptApp As Object
    Set pptApp = GetObject(, "Powerpoint.Application")
    Set act = pptApp.ActivePresentation
    MsgBox act.Slides(1).Shapes("LinkedBox").TextFrame.TextRange.Text
    With act.Slides(1).Shapes("LinkedBox").ActionSettings(ppMouseClick)
        .Action = ppActionHyperlink
        .Hyperlink.Address = "http://www.cnn.com"
    End With
End Sub
    

I have an empty slide with one box on it named "LinkedBox" with the text "Link" in it. The MsgBox appropriately shows "Link" but it fails on the ActionSettings line.

What's wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source