Execute menu commands in powerpoint - vba

I have a custom plugin that was made for powerpoint and has a functionality to export the current slide as HTML5. It doesn't support exporting the entire PPT so basically I would have to go slide by slide and export.
My question is, can I write something in VB that can execute a menu command, finish, next slide, execute menu command etc?
I don't even know if VB would be the correct language to use. I've never written anything in it.

VBA might be simpler since it's built into PowerPoint.
If you know the name of the command bar and the control on the command bar that you want to launch:
Sub LaunchTheCommand()
Dim oCmdbar As CommandBar
Set oCmdbar = Application.CommandBars("CommandBarName")
oCmdbar.Controls("ControlName").Execute
End Sub
View | Toolbars will show you the names of your toolbars.
This could help you work out the right name for the individual controls:
Sub ShowTheControlNames()
Dim oCmdbar As CommandBar
Dim oCtl As CommandBarControl
' for example, let's look at the Standard toolbar:
Set oCmdbar = Application.CommandBars("Standard")
For Each oCtl In oCmdbar.Controls
Debug.Print oCtl.Caption
Next
End Sub
Note that your code won't work on non-English versions of PowerPoint ... the menu names are different.

Related

Add clickable checkbox to powerpoint slide on Mac

I want to add a clickable checkbox (one or more) to a PowerPoint presentation slide. I'm using MacOS and Microsoft Office 365.
I guess that it is possible to do using macros created with VBA, but I have no idea what code needs to be created for this.
I would be very grateful if you would share the necessary code or suggest me another relevant ways to create clickable checkboxes in pptx under the Mac.
Checkboxes, labels, textboxes etc are all ActiveX features, and since ActiveX isn't supported on the Mac version of Office or in MacOS generally, you can't do this the way you would in Windows versions of Office.
You might be able to fake it by adding drawn rectangles and assigning a Run Macro action setting to each of them.
This page on the PPT FAQ that I maintain explains how to write the macro.
Determine which shape was clicked
https://www.pptfaq.com/FAQ00141_Determine_which_shape_was_clicked.htm
TL;DR - here's some sample code. This runs on both Windows and Mac (where bugs in PPT's VBA model force it to be more complicated than it would be otherwise):
Sub DoSomethingTo(oSh as Shape)
Dim oSl as Slide
Dim oShTemp as Shape
' oSh.Parent returns a valid reference to the shape's host slide:
Set oSl = ActivePresentation.Slides(oSh.Parent.SlideIndex)
' and oSh.Name works:
MsgBox oSh.Name
' So we use those two bits to get a reference
' to the clicked shape like so
Set oShTemp = oSl.Shapes(oSh.Name)
With oShTemp
.TextFrame.TextRange.Text = oSh.Name
' and whatever else you want to do with the shape
End With
End Sub

VBA Powerpoint : what is the VBA equivalent to "hyperlink to a different Powerpoint Presentation?

I want to use several slideshows (in kiosk mode if possible), to be able to jump between them, without going back in edit mode...
No problem to do it with shapes and "hyperlink to a different powerpoint presentation".
But i'd need to do it also in VBA macros, in some slides.
For example, after a quiz is finished, jump to another slideshowwindow and a given slide, and give focus to that slideshowwindow :
What would be the code like ?
I'm unable to give focus to the new slideshowwindow...
I suppose it is the equivalent of what "hyperlink to a different PPT Presentation does, but i can't figure to do it.
Thank you very much in advance !
Alex
This Code opens a Presentation goes to Slide Number 5 and starts in Kiosk Mode
Dim PowerPointApp As PowerPoint.Application
Dim myPPT As PowerPoint.Presentation
'Open the Slideshow
Set myPPT = PowerPointApp.Presentations.Open(FileName:="filename.pptx")
Application.ActivePresentation.SlideShowSettings.ShowType = ppShowTypeKiosk
'You need this to work
ActivePresentation.SlideShowWindow.View.Exit
ActivePresentation.SlideShowSettings.Run
'Goto Slide number 5
myPPT.Windows(1).View.GotoSlide 5
'Start Slide Show
myPPT.SlideShowSettings.Run

Pause VBA Word macro, allow user to make a selection, and restart where it left off

I have a requirement for VBA script in Microsoft Word to pause so that the user can select text that will be copied to the clipboard so that it can exported to an Excel file. The user will make a number of selections and finally indicate he/she is done when the contents of the clipboard will be copied to a template Excel file.
I have the code working to copy each selection to the clipboard and then all rows to the Excel file. But I need assistence in figuring out how to pause the code to allow the user to make the selection and then restart the code to copy the selection to the clipboard. I am able to get the userform with toggle switch to switch states and labels when pressed. But have not figured out how to pause the VBA code to allow the user to navigate to the next section of the Word document for the next selection.
The Stakeoverflow question/answer below appears to address this requirement but I have not been able to get it to work. It appears that the code is incomplete.
Pause VBA macro, allow user to make a selection, and restart where it left off
Can someone provide example VBA code that accomplishes this?
Your assistence is much appreciated as I have been beating my head against the wall and it is starting to hurt!
There's no way in VBA to "pause" a macro. Code must run to completion... Unless there's a command for user input.
Input can be requested via the InputBox and MsgBox methods, but those block access to the document because they're modal. A UserForm, however, can be set to display as non-modal, meaning it stays on top, but doesn't block access to the document or the application features. Since you're already working with a UserForm, this can be implemented relatively easily.
In the small example below, the Continue button runs the code to perform an action on the user selection. When Done is clicked the entire code is exited and the form unloaded.
Code behind the user form
Option Explicit
Private Sub cmdContinue_Click()
Debug.Print Selection.Range.Text
End Sub
Private Sub cmdDone_Click()
Me.Hide
End Sub
Private Sub UserForm_Activate()
'Position the form near the top-left of the window
'So that the user can work with the document
Me.Top = Application.ActiveWindow.Top + 50
Me.Left = Application.ActiveWindow.Left + 50
End Sub
Code in a regular module
Option Explicit
Sub DisplayModeless()
Dim frm As frmModelessForInput
Set frm = New frmModelessForInput
frm.Show False 'Display as non-modal
Set frm = Nothing
End Sub

How do you run vba code when changing slides in powerpoint?

I'm trying to reset the contents of some text boxes and labels when I change slides, but I'm struggling to get it to work. I've come up with this after doing a lot of googling and searching, but it doesn't seem to work. I'm trying to use the OnSlideShowPageChange event in PowerPoint 2013 and 2016, but it seems to have no effect. I'm not used to working with PowerPoint vba, so I might be doing something completely wrong.
Edit: I've managed to find an alternative method of resetting the label text. I've managed to get it to reset when the user focuses on one of the text boxes or moves their mouse over the label. But, I'm still curious to know the answer to this question; I'm not sure why my code isn't working.
I'll be greatful if anyone can point out any issues and how to fix them.
Here's what I've got so far:
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
Dim Sld As Slide
If Wn.View.CurrentShowPosition = 9 Then
'Perform Updates for slide #9
Set Sld = Application.ActivePresentation.Slides(9)
Sld.Shapes(TextBox_Form_Name).TextFrame.TextRange.Text = ""
Sld.Shapes(TextBox_Form_Email).TextFrame.TextRange.Text = ""
Sld.Shapes(TextBox_Form_Message).TextFrame.TextRange.Text = ""
Sld.Shapes(Label_Form_Info).TextFrame.TextRange.Text = ""
End If
If Wn.View.CurrentShowPosition = 18 Then
'Perform Updates for slide #18
Set Sld = Application.ActivePresentation.Slides(18)
Sld.Shapes(TextBox_Form_Name).TextFrame.TextRange.Text = ""
Sld.Shapes(TextBox_Form_Email).TextFrame.TextRange.Text = ""
Sld.Shapes(TextBox_Form_Message).TextFrame.TextRange.Text = ""
Sld.Shapes(Label_Form_Info).TextFrame.TextRange.Text = ""
End If
End Sub
I've also tried putting the shape names in speech marks, but that doesn't seem to help.
By the way, I need the code to work in both PowerPoint 2013 and 2016.
Here's an answer from the PowerPoint FAQ at http://www.pptfaq.com
Suppose your code that depends on the OnSlideShowPageChange( SHW as SlideshowWindow ) event works when run from within VBA or when you launch the presentation from within PowerPoint, but not when you start the show by doubleclicking the icon for the PPS or PPSM. The slide show launches normally, but the code in your OnSlideShowPageChange subroutine never runs.
Solution
Add an Active-X control (from the Developer tab) on first slide (drag it just off the slide if you don't want it visible during the slide show).
This forces VBA to initialize when the presentation starts, so the event gets triggered and your code runs.

PowerPoint Text to Speech Macro

I want to be able to create a macro that will start text-to-speech on the text that is in the presenters notes. I will be applying the macro to a ActiveX button that will allow the user to start the reading and eventaully I would like to time the animations of the slides to the speech.
I have sucess in Excel VBA in being able to write out the command to speak a cell with:
application.speech.speak (sheet1.cells(1,1))
and I found a code that will enter text into the speaker notes section for all slides.
Sub AddTextAllSpeakerNotes()
Dim sld As Slide
For Each sld In ActivePresentation.Slides
sld.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange = ""
Next sld
End Sub
I have added the Microsoft Speech Object Library reference, but I can never get the VBA to recognize the speech commands and auto-complete any commands that will help me figure out how to get any further.
How can I write a code that will apply the text-to-speech command to the speaker notes section of a particular slide.
As commented, you can try this:
Dim XL As Excel.Application
Set XL = New Excel.Application
XL.Speech.Speak "I was able to make power point speak"
Provided you added reference to:
Microsoft Excel XX.X Object Library
Once you've bound Excel to PowerPoint, you can directly use its methods from there. In above code, you can simply replace the argument with the actual PPT object that contains the string you want spoken. HTH.