PowerPoint VBA to open an embedded PowerPoint deck for edits - vba

I have a PowerPoint deck and in that deck is a slide with 6 other embedded PowerPoint decks. I want to create VBA code to open each embedded deck, make some changes (which I have the code for), then save (still embedded in the first deck) and close them.
Is there a way to do this within PowerPoint VBA or do I need to use Excel to get this done?
Bonus question - is Microsoft making changes to PowerPoint? They have removed the record macro button, there is almost no support for PowerPoint VBA online (that I have seen. It is all Excel VBA). When they got rid of I.E. they shut down support for HTAs and I am wondering if something similar is happening.
Have tried Open.Presentation, but can't get it to work.

Related

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://learn.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://learn.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.

PowerPoint VBA code not running unless VB editor opened first

I have a PowerPoint presentation which consists of a single slide and some VBA code. The code displays a dialog box (not inside the presentation) which configures the slide.
I need the code to be started when the presentation is started.
I found various suggestions and ended up going with
this one however I am getting inconsistent results!
If I do the following, in sequence, it works:
Open presentation in PowerPoint
Select Developer tab
Select Visual Basic (to open VBA editor)
Close VBA editor
Select Slide Show tab
Select From Beginning
However, if I skip steps 2-4, it does not! I.E.:
1. Open presentation in PowerPoint
2. Select Slide Show tab
3. Select From Beginning
It is almost as though Visual Basic support isn't even loading until the editor is opened.
I also tried adding a slide before my main one with an auto-transition immediately and again, no-go.
This is driving me insane as I need to get this deployed to the rest of my department.
Anyone have any ideas?
It's kind of a known problem.
OnSlideShowPageChange sometimes doesn't fire. To get around it, add any of the Active-X controls from the Developer tab to the first slide. Scoot it off the slide if you don't want it visible.
Somehow the control forces VBA to initialize, so events fire.
After I did this with your presentation, it fired off right away.

Office VBA- detect PowerPoint slide change

I'm creating an application where I'd like to be able to show users an ongoing PowerPoint presentation over the web, where the slide changes as the presenter does so in real time. I've looked at the Office VBA documentation and I didn't see any event for this. The closest I've come are these events, but I don't see anyway of doing what I need to using these.
How can I detect slide changes in Microsoft Powerpoint using Visual Basic?
It seems that this is what you are looking for: Application.SlideShowNextSlide Event
This is VBA Powerpoint object model though, but you should be able to find your way around...

How to put a button into Quick Access Toolbar in MS Word 2010 with a macro (VBA)?

I import bsa file as module. And macro run properly. I need to set up these macros buttons in to Quick Access Toolbar (QAT). I do it manually from standart way as well. But i want to make this automatically with macro (VBA). How these macros assigned to the buttons and buttons set up on the QAT by VBA inside macro?
I searched a lot, and the only way I was able to find was using Office Fluent User Interface.
See this article that walks you through doing it. The example is Excel's QAT, but since all Office Products share the same Type Library, you should be able to adapt it for MS Word 2010.

Standalone code for Excel

Can VBA code be written to perform actions on any Excel file?
When I create a project in Visual Studio, it asks for an Excel file to be linked to it. All the code that I write is in ThisWorkbook.vb and hence acts only on the Excel file linked to the project.
Ideally, I want a script that:
When the user double-clicks, he/she should be allowed to select an Excel file of choice for the actions to be performed on that file.
If the above is not possible, I'd at least like to invoke the VBA script from within an Excel file.
Basically, the VBA code should be independent of any Excel file.
I looked at VBScript, but the syntax for it seems to differ slightly.
You've mentioned Visual Studio, VBA, and VBScript. The solution I'm outlining works directly with VBA rather than Visual Studio or VBScript. (However, you might adapt Visual Studio (C# or VB) along the lines of what I'm outlining below.) Hope it's helpful, so here goes:
Here's what I do, and, it ultimately results in an .xlam Excel AddIn as #chris above has commented.
Overview
I start with ordinary .xslx workbook, to which I add a VBA project, making it an .xlsm. Then create some VBA Subs (macros). Then create some Excel QAT (Quick Access Toolbar) buttons for the workbook, which are bound to (i.e. they invoke) the VBA subs/macros. Then convert the workbook (with VBA in it) to an .xlam, which is an Excel AddIn. When you're all done, the buttons are accessible from any workbook (and the VBA code has access to any user workbooks as well as those originally in your .xlsm). Further, the workbook associated with the .xlam is invisible. So it just looks like you've added some buttons to the QAT that appear on all users .xlsx windows. The .xlam is pretty easy for users to install (though I provide a buttons to uninstall/reinstall/check version). You can upgrade an .xlam independently of users' workbooks; users' workbooks can thus be data only (.xlsx, no VBA).
Details
Write some Excel Subs you want to use later
You need to be aware that the buttons can only invoke macros (VBA Subs) without parameters, so the macros will have to check things like ActiveSheet and ActiveWorkbook and Selection to figure on what sheet the button was pressed, hence what user data to really operate on. (If you need to refer to your workbook with the VBA code in it, use “ThisWorkbook”). You should be aware that there can be naming conflicts, so try to name the parameterless subs with rather long names, such as MySomewhatUniqueProjectName_button1, etc…
Add Buttons to your .xlsm
Using Excel 2010 (I think this works with 2007 or later), I put workbook-specific buttons on the QAT part of the ribbon, which connect to macros (VBA subs) in the VBA code.
To do this, you from the Quick Access Toolbar customization drop down (the tiny down arrow at the very top row of the Excel window, the last icon from left to right) choose "More Commands…". When the “Customize Quick Access Toolbar” dialog box comes up, from the (2nd) "Customize Quick Access Toolbar:" heading (top to the right), choose "For XYZ.xlsm" from the dropdown instead of the "For all documents (default)". And from under "Choose Commands From:", use "Macros" (instead of “Popular Commands”) from the dropdown. Once you have those two things selected, you can move VBA subs from the left box to the right box using “Add >>”. Each so moved will become buttons visible in your QAT. As you’re doing this you can also edit the icon and text for the buttons, add a separator as needed (I always end with a separator in case other .xlam’s use the QAT). (Now is a good time to save this .xlsm.)
Convert the .xlsm into a .xlam
Then I convert the .xlsm to an Excel add-in, by merely saving it as an .xlam file. This will end up (1) hiding the workbook associated with the code you have (though it is still accessible to itself.). Further, now, (2) the (invisible, as now it's an .xlam) workbook will load whenever Excel is loaded. (To keep this fast for when users use Excel but don’t run my VBA code, I don't run any code when the .xlam is loaded, I only run code when a button is pushed.)
You can manage the AddIn using Excel’s AddIn manager. To update the AddIn, you have to use some trickery. While you can copy over it when Excel is not running, on the other hand, you cannot directly uninstall the AddIn, you can only disable it from Excel. But once disabled, you can delete the .xlam, and relaunch Excel, go to the AddIn manager to try to work with the (now gone) AddIn and you’ll get Excel saying it can’t find it, so do you want to delete it. Say yes, and it will be uninstalled.
FYI, Notes
I keep the .xlsm to edit later, but you can actually debug and edit the .xlam and later convert it back to an .xlsm with a minor bit of trickery: find its "ThisWorkbook" entry in VBA, and then the "IsAddIn" property, set to false, its workbook will suddenly appear and you can save as .xlsm, or edit its workbook and set the property back to true to resave as .xlam directly.)
Answer 1
You can do that in VB.Net too. Just make a regular project. (comment by #SLaks)
This worked for me very well and was exactly what I was looking for.
Answer 2
The very descriptive answer posted by #ErikEidt
I haven't tried this, but it seems like a good and alternative way of getting macros to work.