Auto-execution options?

  • Thread starter Thread starter Toby Erkson
  • Start date Start date
T

Toby Erkson

Okay, I've done a search and came up with nothing. Why oh why is PP so
extremely weak when it comes to command-line options and event driven
functionality? I need at least one way (if not more) to automate PP.

In my search I found the AutoEvents add-in by Shyam Pillai but it is not
reliable (I'm about to email him for assistance). For example, it doesn't
always run the Auto_Open() event. If it does, the VBA command
Application.Quit creates an error! I need something reliable. Heck, even a
command-line option to run a macro would be great! Any help/suggestions?

Thanks,

Toby Erkson
Business Intelligence, Inc.
 
Okay, I've done a search and came up with nothing. Why oh why is PP so
extremely weak when it comes to command-line options and event driven
functionality? I need at least one way (if not more) to automate PP.

We'd need more info. There's not much available from the command line, true,
but you can automate PPT and invoke macros from within another program.

See example below


In very round numbers:

Sub RunPPT-InvokeMacro()
' Execute Powerpoint and invoke the macro EXAMPLE
' EXAMPLE must be available to PPT, in an auto-loaded add-in, for example

' Start PowerPoint
Dim oPPTApp As PowerPoint.Application

On Error Resume Next
Set oPPTApp = New PowerPoint.Application
oPPTApp.Visible = True

' Were we able to start PPT?
If Err.Number <> 0 Then
oPPTApp.Quit
Set oPPTApp = Nothing
Exit Sub
End If

' Insert other error/sanity checks here to ensure that there really is an
instance
' of PPT loaded

' Having established that PPT is loaded you could also test for the presence of
the expected add-in
Dim lTemp as Long
Dim bAddinLoaded as Boolean
For lTemp = 1 to oPPTApp.Addins.Count
if oPPTApp.Addins(lTemp) = "YourAddin" then
bAddinLoaded = True
end if
Next lTemp

if not bAddinLoaded Then
oPPTApp.Quit
Set oPPTApp = Nothing
Exit Sub
End if

' Pass control to PPT2HTMLBatch Add-in
oPPTApp.Run "EXAMPLE"

' And quit PPT
oPPTApp.Quit

End Sub


==========================================
If that doesn't help, please post a followup message here.
Visit http://www.rdpslides.com/pptools/ for your free PPTools Starter Kit
and other productivity-enhancing PowerPoint add-ins
 
Hmmm, so indirectly execute a macro...that's an idea I can play with. Thank
you :-) Of course, suggestions from others still appreciated!
 
Working off of Steve's input, plus some browsing through the web, I made
this:
---------------------------------------------
Private Sub Workbook_Open()
' Executing a PowerPoint macro...the indirect way.
Dim PPT As Object

Set PPT = CreateObject("PowerPoint.Application") 'Creates the object
pptDir = "C:\Projects\Automate\" '*
pptFileName = "Daily Orders Dashboard-test.ppt" '*
pptPath = pptDir & pptFileName
PPT.Presentations.Open pptPath, , , False 'Loads the already existing
(specific) object

' Note that the file name and the module name are required to path the macro
correctly.
TheMacroToExecute = "Main" '*
pptMacroPath = pptFileName & "!Module1." & TheMacroToExecute
PPT.Run pptMacroPath 'This snazzy command executes the macro

'Macro is done so quit PPT
PPT.Quit 'Exit the object
Set PPT = Nothing 'Destroy the object (free up memory)

Application.Quit 'Exit Excel
End Sub
---------------------------------------------
Comments that contain an astrick ( '* ) can be changed accordingly for
others who want to use this.

One caveat: The specific PowerPoint file must be already open for this to
work. Since I'll be using a scheduler this is not a problem for me because
I'll have the scheduler launch the PPT file, then this Excel file. Besides,
the links that get updated in the PPT file occur more quickly when there is
an instance of Excel open. This Excel macro then quits the PPT application
and itself. Works for me and my limited VB experience.

There has got to be a way to run this without having to launch the PPT file
first. I need some way -- I'm guessing -- to have the presentation or slide
display otherwise the slides don't seem to appear and the macro fails in
PPT. For example, in Excel, you can activate any particular spreadsheet tab
using the command
Sheets("CONSOLIDATED").Select
Is there a way to do something similar for PPT? To specify a particular
slide? Then I *think* the PPT macro wouldn't fail.

Thanks again!
 
Toby,
You cannot do a Close operation in the Open event of the presentation hence
the error. Application.Quit closes the presentation.
 
' Note that the file name and the module name are required to path the macro
correctly.

See below ...
TheMacroToExecute = "Main" '*
pptMacroPath = pptFileName & "!Module1." & TheMacroToExecute
PPT.Run pptMacroPath 'This snazzy command executes the macro

One caveat: The specific PowerPoint file must be already open for this to
work.

Yes, because your macros are stored in a PPT file.
If you create an addin and install it so that it autoloads with PPT, you get
around that problem.
 
Hmm...yes, that's an alternative (good suggestion!) but I would rather stick
to pure coding if at all possible as it's less complicated/work for my
customer.

Thanks for your help! Much appreciated!!
 
Toby,
Actually Shyam's code example is perfectly reliable. You just aren't
understanding that PPT VBA sometimes works differently from the other
code based stuff we are all used to working in (took us a while too).

PPT coding is similar but different from even the other Office apps
and if you are coming from real VB or something else that is allowed,
then there's often a learning curve since it behaves differently,
abeit on-purpose, even if we don't agree with that purpose.

Brian Reilly, PowerPoint MVP
 
Yeah, PowerPoint definitely has a learning curve to it...difficult when
coming from Excel.

Yes, Shyam's add-in works as long as I don't try to Quit in VB. But then
that doesn't help my automation process. So it's back to the drawing board
:-(
 
Hmm...yes, that's an alternative (good suggestion!) but I would rather stick
to pure coding if at all possible as it's less complicated/work for my
customer.

Not sure what you mean but "pure coding" but keep in mind that your code can
always tell PPT to load an addin on the fly.

Thanks for your help! Much appreciated!!
 
Yes, I understand that. But, admittedly, my VB knowledge is limited so
creating my own add-in with the necessary coding is beyond my capabilities
at this time AND I don't use PPT but Excel so I don't have the time to learn
the intricacies of PPT (which seems to be the runt of the Microsoft Office
litter). My manager links Excel charts into his PPT presentation and wants
to keep it that way so I'm just trying to automate the automatic linking
(Edit/Links...) as best I can.

An add-in is an additional component that needs to be -- obviously :-) --
added in, which means the end user needs to have it. By "pure code" I mean
that there are no additional components that are required like an add-in,
launching another application, calling a macro from another file, etc.
Everything can be done without leaving the VB Module.

I wish I could program even half as good as y'all because I would then know
even more ways to solve my issues but I know that only comes with
experience. I do appreciate the assistance :-)
 
Toby,
I think what you are looking for it this:

Dim PPT As Object
Set PPT = CreateObject("PowerPoint.Application") 'Creates the object
pptDir = "C:\Projects\Automate\" '*
pptFileName = "Daily Orders Dashboard-test.ppt" '*
pptPath = pptDir & pptFileName

Dim oPPTPres As Object

Set oPPTPres = PPT.Presentations.Open(pptPath, , , False)
With oPPTPres
.UpdateLinks
.Save
.Close
End With
Set oPPTPres =Nothing

PPT.Quit 'Exit the object
'Macro is done so quit PPT
Set PPT = Nothing 'Destroy the object (free up memory)

Application.Quit 'Exit Excel
 
Wow, that comes very close!!! It doesn't update all the links, though (?).
Normally, the updating of the links takes about 3 minutes. The below code
executed in less than 1 minute. Checking the .ppt file I can see that only
some links updated and not all. Odd.

The problem may be that in my PPT file all the links are set to Manual. The
macro inside PPT sets the links to automatic, updates them, then sets them
back to manual. This is so the sales guys can open the presentation and it
won't go updating the links on them.

As a test, I just tried to use .Run pptMacroPath in the With...End With and
got a 438 error (Object doesn't support this property or method).

<edit>Is if possible to have a PPT that contains automatic links but save as
a PPT with manual links...hmmm, I think I can do that...wheels turning
now...gotta go!</edit>

Okay, I didn't want to do this because it takes up space but maybe it will
help. Here's the code in my PPT (BTW, the code for switching the linking
between Manual and Automatic is not by me! I forget the source...):
----------
Sub Main()
Call SetLinksToAutoUpdt
ActivePresentation.UpdateLinks 'This is where the magic starts, updating
all Excel links to PPT
Call SetLinksToManualUpdt
ActivePresentation.Save 'Save this updated presentation
End Sub

Sub SetLinksToManualUpdt()
' Sets all embedded Links to Manual updating
Dim sld As Slide
Dim sh As Shape
For Each sld In ActivePresentation.Slides
For Each sh In sld.Shapes
If sh.Type = msoLinkedOLEObject Then
sh.LinkFormat.AutoUpdate = ppUpdateOptionManual 'Set the link
to manual update mode
End If
Next
Next
End Sub

Sub SetLinksToAutoUpdt()
' Sets all embedded Links to Automatic updating
Dim sld As Slide
Dim sh As Shape
For Each sld In ActivePresentation.Slides
For Each sh In sld.Shapes
If sh.Type = msoLinkedOLEObject Then
sh.LinkFormat.AutoUpdate = ppUpdateOptionAutomatic 'Set the
link to automatic update mode
End If
Next
Next
End Sub
----------

Shyam Pillai said:
Toby,
I think what you are looking for it this:

Dim PPT As Object
Set PPT = CreateObject("PowerPoint.Application") 'Creates the object
pptDir = "C:\Projects\Automate\" '*
pptFileName = "Daily Orders Dashboard-test.ppt" '*
pptPath = pptDir & pptFileName

Dim oPPTPres As Object

Set oPPTPres = PPT.Presentations.Open(pptPath, , , False)
With oPPTPres
.UpdateLinks
.Save
.Close
End With
Set oPPTPres =Nothing

PPT.Quit 'Exit the object
'Macro is done so quit PPT
Set PPT = Nothing 'Destroy the object (free up memory)

Application.Quit 'Exit Excel

--
Regards
Shyam Pillai

http://www.mvps.org/skp
....
 
[CRITICAL UPDATE - Anyone using Office 2003 should install the critical
update as soon as possible. From PowerPoint, choose "Help -> Check for
Updates".]

Hello,

If you (or anyone else reading this message) think that it's important that
PowerPoint provide additional functionality in these areas (macro
execution, command lines, etc.), don't forget to send your feedback (in
YOUR OWN WORDS, please) to Microsoft at:

http://register.microsoft.com/mswish/suggestion.asp

As with all product suggestions, it's important that you not just state
your wish but also WHY it is important to you that your product suggestion
be implemented by Microsoft. Microsoft receives thousands of product
suggestions every day and we read each one but, in any given product
development cycle, there are only sufficient resources to address the ones
that are most important to our customers so take the extra time to state
your case as clearly and completely as possible.

IMPORTANT: Each submission should be a single suggestion (not a list of
suggestions).

John Langhans
Microsoft Corporation
Supportability Program Manager
Microsoft Office PowerPoint for Windows
Microsoft Office Picture Manager for Windows

For FAQ's, highlights and top issues, visit the Microsoft PowerPoint
support center at: http://support.microsoft.com/default.aspx?pr=ppt
Search the Microsoft Knowledge Base at:
http://support.microsoft.com/default.aspx?pr=kbhowto

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
I am assuming that the SetLinksToManualUpdt code is identical to the one on
the following page?
http://www.mvps.org/skp/ppt00029.htm. Copy the two routines below into your
excel code module and modify your exisiting code as show below:

Sub SetLinksToAutoUpdt(oPres As Object)

Dim sld As Object
Dim sh As Object
For Each sld In oPres.Slides
For Each sh In sld.Shapes
If sh.Type = 10 Then
' Set the link to automatic update mode
sh.LinkFormat.AutoUpdate = 2
End If
Next sh
Next sld
End Sub


Sub SetLinksToManualUpdt(oPres As Object)
Dim sld As Object
Dim sh As Object
For Each sld In oPres.Slides
For Each sh In sld.Shapes
If sh.Type = 10 Then
' Set the link to manual update mode
sh.LinkFormat.AutoUpdate = 1
End If
Next sh
Next sld
End Sub

Dim PPT As Object
Set PPT = CreateObject("PowerPoint.Application") 'Creates the object
pptDir = "C:\Projects\Automate\" '*
pptFileName = "Daily Orders Dashboard-test.ppt" '*
pptPath = pptDir & pptFileName

Dim oPPTPres As Object

Set oPPTPres = PPT.Presentations.Open(pptPath, , , False)
With oPPTPres
Call SetLinksToAutoUpdt(oPPTPres) ' new line
.UpdateLinks
Call SetLinksToManualUpdt(oPPTPres) 'new line

.Save
.Close
End With
Set oPPTPres = Nothing

PPT.Quit 'Exit the object
'Macro is done so quit PPT
Set PPT = Nothing 'Destroy the object (free up memory)

Application.Quit 'Exit Excel
 
I got an error but it was because of this:
PPT.Presentations.Open Filename:=pptPath 'Loads the already existing (specific) object
So I removed that line from my [original] code.

Then everything worked except when it was time to save the updated presentation. In the With...End With the ".Save" stops execution with the following error, "Presentation.Save: This presentation is read-only and must be saved with a different name." followed by the "End" and "Debug" buttons.

After looking at the PPT Help file for Open, I changed this line
Set oPPTPres = PPT.Presentations.Open(pptPath, , , False)
to this
Set oPPTPres = PPT.Presentations.Open(pptPath, ReadOnly:=msoFalse)

Tested...and...IT WORKS!

Shyam, my man, you ROCK!! Basically what you've shown me is that I can remove a simple macro from one application and run it in another :-) Plus you've given me a fine example using objects; an area where I need to improve my skills.

Steve, thanks for your help as well, it made me play with the code and think of other possibilities.

Here is the code I'm using...feel free to use it for any FAQ or hints/help pages y'all may have:
---------------
Private Sub Workbook_Open()
'Note: PowerPoint (PPT) must be running when this is executed. PPT should be
'empty (no presentation loaded).

Dim PPT As Object
Dim oPPTPres As Object
Dim pptDir As String
Dim pptFileName As String
Dim pptPath As String

Application.DisplayAlerts = False
Set PPT = CreateObject("PowerPoint.Application") 'Creates the object
pptDir = "Y:\Private-Employees\Dashboard Project\" 'UNC can be used as well
pptFileName = "Daily Orders Dashboard.ppt"
pptPath = pptDir & pptFileName

Set oPPTPres = PPT.Presentations.Open(pptPath, ReadOnly:=msoFalse) 'Opens the presentation object as read/write
With oPPTPres
Call SetLinksToAutoUpdt(oPPTPres)
.UpdateLinks
Call SetLinksToManualUpdt(oPPTPres)
.Save
.Close
End With
Set oPPTPres = Nothing 'Destroy the object (free up memory)
PPT.Quit 'Exit the object
Set PPT = Nothing 'Destroy the object (free up memory)

Application.DisplayAlerts = True
Application.Quit 'Exit Excel
End Sub
-----
Sub SetLinksToAutoUpdt(oPres As Object)
Dim sld As Object
Dim sh As Object
For Each sld In oPres.Slides
For Each sh In sld.Shapes
If sh.Type = 10 Then
sh.LinkFormat.AutoUpdate = 2 'Set links to Automatic update mode
End If
Next sh
Next sld
End Sub
-----
Sub SetLinksToManualUpdt(oPres As Object)
Dim sld As Object
Dim sh As Object
For Each sld In oPres.Slides
For Each sh In sld.Shapes
If sh.Type = 10 Then
sh.LinkFormat.AutoUpdate = 1 'Set links to Manual update mode
End If
Next sh
Next sld
End Sub
---------------

Shyam Pillai said:
I am assuming that the SetLinksToManualUpdt code is identical to the one on
the following page?
http://www.mvps.org/skp/ppt00029.htm. Copy the two routines below into your
excel code module and modify your exisiting code as show below:

Sub SetLinksToAutoUpdt(oPres As Object)

Dim sld As Object
Dim sh As Object
For Each sld In oPres.Slides
For Each sh In sld.Shapes
If sh.Type = 10 Then
' Set the link to automatic update mode
sh.LinkFormat.AutoUpdate = 2
End If
Next sh
Next sld
End Sub


Sub SetLinksToManualUpdt(oPres As Object)
Dim sld As Object
Dim sh As Object
For Each sld In oPres.Slides
For Each sh In sld.Shapes
If sh.Type = 10 Then
' Set the link to manual update mode
sh.LinkFormat.AutoUpdate = 1
End If
Next sh
Next sld
End Sub

Dim PPT As Object
Set PPT = CreateObject("PowerPoint.Application") 'Creates the object
pptDir = "C:\Projects\Automate\" '*
pptFileName = "Daily Orders Dashboard-test.ppt" '*
pptPath = pptDir & pptFileName

Dim oPPTPres As Object

Set oPPTPres = PPT.Presentations.Open(pptPath, , , False)
With oPPTPres
Call SetLinksToAutoUpdt(oPPTPres) ' new line
.UpdateLinks
Call SetLinksToManualUpdt(oPPTPres) 'new line

.Save
.Close
End With
Set oPPTPres = Nothing

PPT.Quit 'Exit the object
'Macro is done so quit PPT
Set PPT = Nothing 'Destroy the object (free up memory)

Application.Quit 'Exit Excel
....
 
Back
Top