Solved

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

Posted on 2011-02-17
15
645 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spell checking an unbound form in MS Access 2013 9 57
Recursive folder search vbscript 7 40
Word 2016 - Comments on one page contracted 2 45
Problem to With line 4 41
This article will show you how to use shortcut menus in the Access run-time environment.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

911 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

22 Experts available now in Live!

Get 1:1 Help Now