简体   繁体   中英

VBA for Powerpoint: Change Slide in One Powerpoint by Selecting Button in Another

I am a beginner at VBA.

I am designing a somewhat interactive Powerpoint presentation/s. I want to be able to have three separate Powerpoint presentations open that will link together. I have been trying (without success) to create, in VBA, code which will change the current displayed slide on one Powerpoint file by clicking a button in another. I can hyperlink to the set slide but this causes this slide to pop up on the same screen in which it is clicked, despite it being already open in another screen (I don't want this).

Thanks in advance for any help, Holly

VBA uses an object model that is a huge hierarchy of attributes and functions that represent the application. You can use this model to view and update attributes to get text, resize, and modify the application. You should look at some tutorials to get you started. When editing your code, you can press F2 to see and explore this object model. You can press F8 to run your code line by line (debug mode) and see what is happening. To your question, you can access the open presentations in the application.presentations object ( https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentations ). You could then use a presentation in that list and use the ActiveWindow.View.goToSlide function ( https://docs.microsoft.com/en-us/office/vba/api/powerpoint.view.gotoslide ). Here is a free tutorial that I've used in my VBA journey ( https://www.tutorialspoint.com/vba/index.htm ).

PowerPoint has a Presentations collection that contains all currently open presentations. You can get a reference to any of them via Presentations("name") where "name" is the filename of the presentation, sans extension.

So ... assuming you've got three presentations open, a.pptx, b.pptx, c.pptx you can do something like this:

Sub SlideChange()
    With Presentations("c")
        .SlideShowWindow.View.GotoSlide (3)
    End With
End Sub

If you run the above in any of the presentations, it will change the slide show window displaying presentation c to the third slide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM