PDA

View Full Version : VBA fails when ppsm laucnhed from windows explorer, ok in Powerpoint



dlockwood
10-13-2014, 08:21 AM
I have created a quiz using Powerpoint 2007 and VBA code.
I have saved it as a ppsm file so that it can be double clicked from windows explorer and open straight away as a slideshow
I have protected editing with a password to stop users opening it in Powerpoint.

It all works well except my code which runs on the last slide that prints out the slide to the default printer.
I have a button on the last slide that says Print and runs the following macro code to Print the current slide



Sub PrintCurrentSlide()

On Error GoTo lblError:

Dim lSldNum As Long

lSldNum = SlideShowWindows(1).View.Slide.SlideNumber

ActivePresentation.PrintOptions.RangeType = ppPrintSlideRange

ActivePresentation.PrintOptions.Ranges.ClearAll

ActivePresentation.PrintOptions.Ranges.Add lSldNum, lSldNum


ActivePresentation.PrintOut


Exit Sub
lblError:
MsgBox (Err.Number & " : An error has occurred.")
Err.Clear
SendKeys "{ESC}"
Close #1


End Sub


The code I found on Microsoft's own website and runs fine when I open the ppsm file within Powerpoint.

but if I close powerpoint and just double click the ppsm file from windows explorer , the slideshow will start but when it runs the clode to print the last slide I get the error code: -2147467259


I had a similar issue trying to assign text to a shape on a different slide and managed to get round it using an activex label.

Anyone got any ideas?

Cheers

Douglas

edit: after a bit more investigation it seems that the error occurs because I have set a password to modify. When I take the password off then the code works fine.
I would however like to keep the password on as this prevents users opening it up to see the macros that run on the actions.

John Wilson
11-20-2014, 11:51 AM
Your code is modifying the presentation by changing the options. With the password this will not run. You should be able to set a code password in the VBE though.