Solved

Visual Basic Script in PowerPoint not running after file close and reopen

Posted on 2011-02-17
15
644 Views
Last Modified: 2012-05-11
Hello,

I have configured the following Visual Basic module script in my PowerPoint Presentation.  As long as I create a new presentation and write the module, and do not exit from the PowerPoint program, the module will run properly every time I view the show.

However, if I exit from the presentation (after saving), and reopen it, the VB script will no longer execute.  No error messages are given -- the script simply does not run.

If you have any ideas or suggestions, or need further information from me, please do not hesitate to ask.

This is MS PowerPoint 2003 (11.8324.8329) SP3.
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
    Select Case SSW.View.CurrentShowPosition
        Case 1 'slide 1
        Case 2 'slide 2
            Shell "cmd.exe /c " & Chr$(34) & "notepad" & Chr$(34), vbMinimizedFocus
        Case 3 'slide 3
    End Select
End Sub

Open in new window

Thanks for your assistance!
0
Comment
Question by:GenlLeeCSA1
  • 9
  • 6
15 Comments
 
LVL 23

Assisted Solution

by:JSRWilson
JSRWilson earned 500 total points
ID: 34921674
0
 

Author Comment

by:GenlLeeCSA1
ID: 34922341
Thanks, JSRWilson.

Unfortunately, even after following those instructions, in addition to those here, I'm still experiencing the same symptom.

The file I'm using is attached.

Thanks,
- Adam
Video-Test.ppt
0
 

Author Comment

by:GenlLeeCSA1
ID: 34922348
The problem being that everything performs as expected when the code is first written, but no longer works at all once PowerPoint has been closed, and the file re-opened.
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 34932468
As I think my article details Auto_Open will NOT fire when a normal presentation is opened it needs to be in a ppa or ppam AddIn. alternatively you need a button to click to run it when the presentation first shows.
0
 

Author Comment

by:GenlLeeCSA1
ID: 34932619
Thanks for the clarification.

The complication is that I will need different things to execute on different slide numbers from one presentation to another.

Is there a way to have the .ppa file auto-detect which presentation is open (if / elseif statement or the like), and then fire the desired commands at the desired slide numbers based on the results of that detection?
0
 
LVL 23

Assisted Solution

by:JSRWilson
JSRWilson earned 500 total points
ID: 34932771
I would add tags to the slides

ActiveWindow.Selection.ShapeRange(1).Tags.Add "FIRE", "ACTION1" (change the second value as required)

Then have the Add In detect this:
Private Sub PPTEvent_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
Dim osld As Slide
Set osld = Wn.View.Slide
If osld.Tags("FIRE") = "ACTION1" Then ....
End Sub

Open in new window

0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 34937046
Sorry ShapeRange should be SlideRange!
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:GenlLeeCSA1
ID: 34952586
Thanks, JSRWilson.  Where do I add the tag to the slide?  Do I use a class module in the Visual Basic Editor for the presentation, or is there another procedure?

Here is the (non-functional) code I have in place as things stand.  The goal is to launch the program "notepad" when the second slide in the presentation is displayed.  The add-in is saved correctly, and loads properly when PowerPoint launches.  However, Notepad does not start.

VBA for Add-In File (Notepad Start.ppa) Module
Public cPPTObject As New cEventClass
 
Sub Auto_Open()
     'Set a application reference to the event-enabled object
    Set cPPTObject.PPTEvent = Application
End Sub

Open in new window

VBA for Add-In File (Notepad Start.ppa) Class Module "cEventClass"
Public WithEvents PPTEvent As Application
Private Sub PPTEvent_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
    Dim osld As Slide
    osld = Wn.View.Slide
    If osld.Tags("FIRE") = "ACTION1" Then
        Shell "notepad"
    End If
End Sub

Open in new window

VBA for Presentation File (Notepad Test.ppt) Class Module
ActivePresentation.Slides(2).Tags.Add "FIRE", "ACTION1"

Open in new window

0
 

Author Comment

by:GenlLeeCSA1
ID: 34952604
The same thing occurs if "SlideRange" is used instead of "Slides" in the presentation file's class module.
0
 

Author Comment

by:GenlLeeCSA1
ID: 34952703
I just noted the error in line 4 of the VBA for the Add-In file.  I corrected the error, but still have no launch of the Notepad program on slide two of the Notepad Test.ppt presentation.

The code for the class module for the Notepad Start.ppa file, now unloaded and re-loaded with the corrections, now reads:

Public WithEvents PPTEvent As Application
Private Sub PPTEvent_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
    Dim osld As Slide
    Set osld = Wn.View.Slide
    If osld.Tags("FIRE") = "ACTION1" Then
        Shell "notepad"
    End If
End Sub

Open in new window


Thanks,
- Adam
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 34953479
And you saved the code as an addin and loaded it through AddIns >>Add new?
0
 

Author Comment

by:GenlLeeCSA1
ID: 34953495
Yes, that is correct.
0
 

Author Comment

by:GenlLeeCSA1
ID: 34953943
I'm attaching two files for your review.  I'm attaching the .ppa file as the source .ppt file so that the code can be accessed and viewed.  It is saved as a .ppa and loaded as an add-in on my system.
Start-Notepad.ppt
Notepad-Test.ppt
0
 
LVL 23

Accepted Solution

by:
JSRWilson earned 500 total points
ID: 34963423
Made some minor changes. Main problem is the tagging code. It needs to be RUN from a normal module. See attached


Notepad-Test.ppt
Start-Notepad.ppt
0
 

Author Comment

by:GenlLeeCSA1
ID: 34974250
It works great, JSRWilson.  Thanks so much for your efforts!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Outlook Free & Paid Tools
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now