Solved

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

Posted on 2011-02-17
15
647 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Excel formula on dynamic data 5 42
VBA name newly created sheet 4 24
Excel Spacing Anomaly 4 23
sumifs excel 2013 3 15
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

773 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