Link to home
Start Free TrialLog in
Avatar of Jon Bredensteiner
Jon BredensteinerFlag for United States of America

asked on

How can I use PowerPoint VBA to assign [Alt-Tab] to an action button.

Is it possible to assign the [Alt+Tab] keyboard shortcut to an action button in PowerPoint, and if so can you show me how to write the VBA?

Thank you in advance for your help,
   Jon
SOLUTION
Avatar of John Wilson
John Wilson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jon Bredensteiner

ASKER

Thank you for your help...

I tried the code you provided, but I received the following error:

"
Compile error:
Method or data member not found
"

and it highlighted the "SendKeys" in the code.

I am trying to use an Excel file as a Dashboard to run four large PowerPoint files (around 75 slides each).  I would like the user to be able to open the Excel file from anywhere, and then use hyperlinks in the Excel file to navigate to custom slide shows in the various .ppsm files.

The problem is that if I use an action button to close the slideshow every time the user wants to go back to the dashboard the .ppsm files will completely close, and thus have to be reopened (over the network) every time a link on the dashboard is selected.

I cannot simply use a hyperlink in the .ppsm files to navigate back to the Excel file either, because we are trying to make the Excel file portable, so it can be distributed via emailed.

Let me know if you need more information, and thanks again for your assistance.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm wondering why you are using Excel as the dashboard. Wouldn't it be easier to create the dashboard in PPT?
Sorry guys, I've been out of the office sick this this week, so I have some catching up to do, but I haven't forgotten about this question.  I will respond ASAP.

Thank you both for your help,
   Jon
Okay, Jamie's SendKeys macro worked

Sub AltTab()
    SendKeys ("%{TAB}")
    DoEvents
End Sub

Open in new window


I tried your other code Jamie, but I could not get it to work.  I wasn't sure exactly how to use it, so I tried it in a .pptm file, assigning action buttons to each of the macros, but it didn't seem to do anything.

I also tried putting the code into Excel, and it caused an error saying it expected an End Sub, and highlighted the following line

' Assign macro to relevant action button

Anyway, you answered my question Jamie, so I'll definitely assign you the points; however, I do see what you were both saying about not mimicking key strokes, so I'll probably find another solution to my problem.
Sub AltTab()
    SendKeys ("%{TAB}")
    DoEvents
End Sub
Sorry my original code has two errors in it. Both occurrences of Exit Sub should in fact be End Sub. I can't seem to edit the comment now.
Thanks Jamie,

Is the below code supposed to go in a .pptm file or a .xlsm file?  I'm pretty sure .xlsm is correct.


' Start a slide show
Public appPPT as Object
Public objPres as Object

' Start a slide show
' Assign macro to relevant action button
Sub StartSlideShow()
  Const FilePathAndName = "C:\Temp\example.pptm"
  ' Create an instance of PowerPoint
  Set appPPT = CreateObject("Application.PowerPoint")
  ' Open a given PowerPoint file
  Set objPres = appPPT.Open(FilePathAndName, msoTrue, msoFalse, msoTrue)
  ' Run a slide show
  appPPT.Presentations(1).SlideShowSettings.Run
End Sub

' Exit the Slide Show
' Assign macro to relevant action button
Sub ExitSlideShow(objSSW as Object)
  appPPT.SlideShowWindows(1).View.Exit
End Sub

' Close a presentation
Sub ClosePres()
  objPres.Close
End Sub

' Tidy Up (run when closing Excel VBA project)
Sub Tidy()
  Set objPres = Nothing
  Set appPPT = Nothing
End Sub

Open in new window

I hadn't checked the code but have now. This works:

Option Explicit

' Macros for opening a presentation, starting and stopping a slide show
' Runs from any VBE, including Excel (uses late binding)

' Define late bound objects for PowerPoint application instance and presentation
Public appPPT As Object
Public objPres As Object

' Start a slide show
' Set FilePathAndName to the presentation file to be opened
' Assign macro to relevant action button
Public Sub StartSlideShow()
  Dim FilePathAndName As String
  FilePathAndName = "c:\temp\test.pptx"
  ' Create an instance of PowerPoint
  Set appPPT = CreateObject("PowerPoint.Application")
  ' Open the PowerPoint file specified by the string variable FilePathAndName
  Set objPres = appPPT.Presentations.Open(FilePathAndName, ReadOnly:=msoFalse, Untitled:=msoFalse, WithWindow:=msoFalse)
  ' Run the slide show
  objPres.SlideShowSettings.Run
End Sub

' Exit the specified Slide Show or the first one if none specified
' Assign macro to relevant action button
Public Sub ExitSlideShow(Optional objSSW As Object)
  If objSSW Is Nothing Then
    appPPT.SlideShowWindows(1).View.exit
  Else
    objSSW.View.exit
  End If
End Sub

' Tidy Up (run when closing Excel VBA project)
Public Sub Tidy()
  Set objPres = Nothing
  Set appPPT = Nothing
End Sub

Open in new window

It almost worked :)  The procedure [StartSlideShow] works to open a presentation in Slide Show mode, but the procedure [ExitSlideShow] is not available to run as a macro.

I opened a new question though, so you can also receive credit for helping me with this problem.

How can one control the start/stop/close actions of PowerPoint presentations from Excel or from another presentation?

Thanks again,
   Jon