Share via

Inserting Action Button using VBA Code in PowerPoint

Anonymous
2012-03-25T20:01:34+00:00

I am able to insert Action Button on my power point slide using VBA code with no problem.   I am also able to control the setting of the Action Button to move to the next slide.   The problem I have is to control the setting of the Action Button to Go To a certain slide number.    I could do this manually by the tool menu, but I want to do this by VBA code .

I have Power Point 2003 which has a Macro Recorder, and this is what I recorded to go to slide 3:

   ActiveWindow.Selection.SlideRange.Shapes("AutoShape 3").Select

   With ActiveWindow.Selection.ShapeRange.ActionSetting(ppMouseClick).Hyperlink

         .Address = ""

         .SubAddress = "258,3,Slide 3"

   End With

When I recorded the macro to go to slide 4, the SubAddress changed to"

        .SubAddress = "259.4,Slide 4"

The problem I have is to determine the starting number like 259 ????   because each slide after that is sequencial.  Different power point slides has that number different too.

I have just 4 slides (in my test case only), and I want the Active Button on Slide one to go to slide 3 and slide 2 to go to slide 4      In reality, I have many slides. for example if there are S slides, and insert S more slides for embedded video.  Therefore the total slides is 2S.  I always want the Action Button of Slide 1 to go to slide S + 1,   Slide 2 Action Button to go to Slide S + 2.

I have tried using a macro that I tried, but the Action button seems no to work with Run Macro where my macro is:

      ActivePresentation.SlideShowWindow.View.GoToSlide (3)   

This doesn't work using the Add-in men from Adobe Presenter 7 which generate a flast for me.   The setting of the Action Setting does work.

I would appreciate any help !!!

Thank You,

G

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-03-25T20:35:42+00:00

The subaddress is a string

"The target SlideID ,Target slideIndex , Target slide title"

So to target slide 3 you could use

Sub actionbutt()

Dim sldID As String

Dim sldInd As String

Dim sldTitle As String

Dim oshp As Shape

'To link to slide 3

With ActivePresentation.Slides(3)

sldID = CStr(.SlideID)

sldInd = CStr(.SlideIndex)

If .Shapes.HasTitle Then sldTitle = .Shapes.Title.TextFrame.TextRange.Text

If sldTitle = "" Then sldTitle = "Slide" & CStr(.SlideIndex)

With ActivePresentation.Slides(1).Shapes

Set oshp = .AddShape(msoShapeActionButtonForwardorNext, 10, 10, 40, 30)

With oshp.ActionSettings(ppMouseClick)

.Action = ppActionHyperlink

.Hyperlink.SubAddress = CStr(sldID) & "," & CStr(sldInd) & "," & sldTitle

End With

End With

End With

End Sub

Note slideIDs may NOT be sequential.

Edit by John Korchok, Sept. 13, 2018:

This may have changed in the last few years, but .Hyperlink.Subaddress only accepts the slide title, not the index or the ID. So only

.Hyperlink.SubAddress = sldTitle

is working here.

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-03-25T23:43:50+00:00

    Thank You for the quick reply !!

    I was only able to respond just now because of electrical power went out for 1.5 hours.

    The SlideID was that number that I was trying to find.

    G

    Was this answer helpful?

    0 comments No comments