PowerPoint VBA Help

R

Rob

All,

I'm having a difficult time trying to work out a seemingly simple task.

I have a staff meeting every 7 days; 11 different work-sections add thier
inputs to the weekly staff meeting slides. It's very importatnt that the
data in the slides be up-to-date, so I created a simple macro to grab each
individual powerpoint presentation from different folders on our LAN and add
them to the "main" slide.

Simple; each presentation is pulled into the main presentation with this
line of code

ActivePresentation.Slides.InsertFromFile "\\LAN Drive\staff
meeting\Operations\Operations.ppt", 1, 1, -1
ActivePresentation.Slides.InsertFromFile "\\LAN Drive\staff
meeting\Training\Training.ppt", 1, 1, -1
ActivePresentation.Slides.InsertFromFile "\\LAN Drive\staff
meeting\Budget\Budget.ppt", 1, 1, -1
etc.
etc.
etc.

My boss wanted to know if the data from the slides was up-to-date (was it
updated since the last meeting?), so I added the following code to add the
date the file was last saved to the Footer of the respective work-sections
title slide if it was older than 7 days old:


Dim MyStamp

MyStamp = FileDateTime(\\LAN Drive\staff
meeting\Operations\Operations.ppt)
If MyStamp < (Now - 7) Then
ActivePresentation.Slides.InsertFromFile "\\LAN Drive\staff
meeting\Operations\Operations.ppt", 1, 1, -1
ActivePresentation.Slides(2).HeadersFooters.Footer.Text = "Last
Updated " & Format(MyStamp)
Else
ActivePresentation.Slides.InsertFromFile "\\LAN Drive\staff
meeting\Operations\Operations.ppt", 1, 1, -1
End If


MyStamp = FileDateTime(\\LAN Drive\staff meeting\Training\Training.ppt)
If MyStamp < (Now - 7) Then
ActivePresentation.Slides.InsertFromFile "\\LAN Drive\staff
meeting\Training\Training.ppt", 1, 1, -1
ActivePresentation.Slides(2).HeadersFooters.Footer.Text = "Last
Updated " & Format(MyStamp)
Else
ActivePresentation.Slides.InsertFromFile \\LAN Drive\staff
meeting\Training\Training.ppt, 1, 1, -1
End If

etc.
etc.

Of course the boss still wasn't happy...if the work-sections data is older
than 7 days, he wants the Last Updated (date) font Color to be red and 14
pitch. I tried doing that with the footer, but I could not figure out how
to do it (maybe you can't).

What I want to do is create a textbox in each work-section title slide
(Which I did; I also formatted the textbox font). I then tried to add the
following code to make it update:

'blah blah blah
MyStamp = FileDateTime(\\LAN Drive\staff
meeting\Operations\Operations.ppt)
If MyStamp < (Now - 7) Then
ActivePresentation.Slides.InsertFromFile "\\LAN Drive\staff
meeting\Operations\Operations.ppt", 1, 1, -1

'*******Here's the code to add the date:***********
With ActivePresentation.Slides(2)
.Shapes("TextBox1").Name = "Last Updated" &
Format(MyStamp, "dd mmm yy")
End With
'******************************************
Else
ActivePresentation.Slides.InsertFromFile "\\LAN Drive\staff
meeting\Operations\Operations.ppt", 1, 1, -1

End If

.....

This will run without errors, but the textbox does not get updated... Can
you programatically update a texbox? Any suggestions?

Rob
 
B

Brian Reilly, MS MVP

Rob, You certainly can. In your case you could have turned on the
macro recorder and gotten enough code to help you write it better than
the recorder does.

e.g.

ActiveWindow.Selection.SlideRange.Shapes.AddLabel(msoTextOrientationHorizontal,
112.375, 81.875, 14.5, 28.875).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoFalse

With ActiveWindow.Selection.TextRange.ParagraphFormat
.LineRuleWithin = msoTrue
.SpaceWithin = 1
.LineRuleBefore = msoTrue
.SpaceBefore = 0.5
.LineRuleAfter = msoTrue
.SpaceAfter = 0
End With


ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1,
Length:=0).Select

With ActiveWindow.Selection.TextRange
.Text = "My new text"

With .Font
.Name = "Arial"
.Size = 18
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With

End With

ActiveWindow.Selection.Unselect

Brian Reilly, PowerPoint MVP
 
R

Rob

Brian,

I tried several times with the Macro recorder and did get a similar result
to what you came up with below. The problem I had was trying to force my
code into a TextBox instead of a TextFrame (a hell of a lot easier!). The
other problem I had was inserting the data into the correct slide; I fixed
this problem once I found out how to point to different slides in the
presentation:

ActivePresentation.Slides(2).Select

Thanks for putting me on the right track... My programming skills are
getting rusty and VB/VBA is tough maze to negotiate if you don't know
EXACTLY what you are looking for.

I do have one problem left... using the code above to move to a different
slide isn't exactly what I want. When I run the Macro, it may move to 5 or
6 title slides that will be updated by my code if a lot of the data is older
than 7 days (kind of unprofessional to watch!). I simply want to move the
focus to the 2nd slide so I can add the data (Last updated: date) if the
inserted presentation is older than 7 days.

How can I do this behind the scenes?

Rob
 
B

Brian Reilly, MS MVP

Rob, Not sure I follow your thoughts here.
Are you just trying to supress the screen repainting looks awful to
the audience? Are you doing this during a slide show, or during a
slide edit session?

Since PPT does not have a ScreenUpdating=False like Excel you have to
rely on an API call to do this. Fellow MVP Shyam Pillai has sample
code on his web site to do this. Google on "Shyam Pillai
ScreenUpdating" and it will lead you to
http://www.mvps.org/skp/ppt00033.htm

Always, first google on "Shyam Pillai" or "PPTFAQ". Lots of great
stuff.

Brian Reilly, PowerPoint MVP
 
R

Rob

Brian,

Thanks for the tip...

One last question. Everything I've done now works, but when I make a change
to the code it fails on this line:

ActiveWindow.Selection.SlideRange.Shapes.AddLabel(msoTextOrientationHorizontal,
112.375, 81.875, 14.5, 28.875).Select

The message is:

Shape (unknown member) : Invalid request. To select a shape, it's view must
be active.

Now for the weird part... All I have to do is delete the slides it created
and run the Macro again -- it will work perfect. I can close the
application and start over and it will always work perfectly.

Any idea why it fails when I make any kind of change?

Rob

112.375, 81.875, 14.5, 28.875).Select
 
S

Shyam Pillai

Rob,
Check the view that your presentation is in. You cannot select a shape
unless it is view which supports shape selection. For example, you cannot
select shapes when you are in the slide sorter view.

Regards,
Shyam Pillai

http://skp.mvps.org/
 
S

Steve Rindsberg

One last question. Everything I've done now works, but when I make a change
to the code it fails on this line:

ActiveWindow.Selection.SlideRange.Shapes.AddLabel(msoTextOrientationHorizontal,
112.375, 81.875, 14.5, 28.875).Select

The message is:

Shape (unknown member) : Invalid request. To select a shape, it's view must
be active.

This is running in SlideShow view, isn't it? That'd be the problem. You can't
select anything in slideshow view, so code that selects something will fail also.
This is one of the problems with code the macro recorder creates.

Instead, try:

call SlideShowWindows(1).View.Slide.Shapes.AddLabel(msoTextOrientationHorizontal,
112.375, 81.875, 14.5, 28.875)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top