PowerPoint Macro stops working after used a few times

B

benedict.ryan

Hi all,

My PowerPoint macro stops work afte rI have used it a few times. First
off, I create the macro and try using it on a few pictures that I have
cut and pasted on to a slide. The macro works fine for about 3-8
slides, but then just stops working--I haven't changed a thing and I am
still working within the same file I created the macro in. Any ideas
why this would happen? I have attached the code below--it is very
basic!

Sub Report()
'
' Macro recorded 8/31/2006 by ryan.benedict
'

ActiveWindow.Selection.SlideRange.Shapes("Picture 3").Select
With ActiveWindow.Selection.ShapeRange
.Fill.Transparency = 0#
.Height = 466.38
.Width = 621.88
End With
ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
ActiveWindow.Selection.ShapeRange.Align msoAlignTops, True
ActiveWindow.Selection.ShapeRange.ScaleHeight 0.98, msoFalse,
msoScaleFromTopLeft

ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizontal,
54, 450, 618, 28.875).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoTrue
With ActiveWindow.Selection.TextRange.ParagraphFormat
.LineRuleWithin = msoTrue
.SpaceWithin = 1
.LineRuleBefore = msoTrue
.SpaceBefore = 0.5
.LineRuleAfter = msoTrue
.SpaceAfter = 0
End With
ActiveWindow.Selection.ShapeRange.IncrementTop 6#
End Sub
 
D

David M. Marcovitz

Here is what looks like the issue to me. The first line of code is trying
to select a shape named Picture 3. If the slide you are on doesn't have
Picture 3, then it will crash the macro, and VBA is very kind by not
bothering to tell you that something has gone wrong; it just doesn't do
anything. My guess is that the slides for which this doesn't work already
had more than two shapes on them when the picture was added (or possibly
had less than two shapes, such as if they were title only slides or blank
slides).

If I am correct, you will have to find a better way to identify the
picture. You can name it yourself, or you can select it before running
your macro. If you can select each picture on each slide, then you could
just eliminate that first line starting with ActiveWindow.

Another alternative would be to write a little macro to find a picture on
the slide.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/

(e-mail address removed) wrote in
 
J

John Wilson

Ryan

Recorder macros are rarely efficient code!

If you explain what you are trying to do I'll maybe be able to write some
code for you.

email if you want and I'll post up any aswers here (john AT
technologytrish.co.uk)
--

Did that answer the question / help?
_____________________________
John Wilson
Microsoft Certified Office Specialist
http://www.technologytrish.co.uk/ppttipshome.html
 
B

benedict.ryan

Both of these posts apply here. It is my guess that some how the macro
is naming a picture title/file name in the first line where it gives
the code "Picture 3". The problem is that I don't know what else I
should call the picture so I can just run the macro clean without any
bugs. The funny thing is that once I create the macro I can use it on
five to eight different slides, but after this time it stops
functioning. Then when I recreate the same macro I get the same
results-a short lived functionality. The code works, but I don't
know enough about creating PowerPoint macros to name this line of code
differently so it works indefinitely.

What I am trying to do is resize a large picture on a slide. I am
cutting and pasting the picture file onto the one slide. All of the
pictures are different. Then I am resizing and aligning it to the top
center of the slide. Then I am adding a text box. It is a really
simple program, but it is for work and I am just trying to save some
time and steps because this is something that I would access quite
often. If you have any ideas, even if it is just to change naming the
picture it would help. Should I be trying to import the pictures
rather that cut and paste, but if I do that won't I be losing some
photo quality (this isn't for a presentation, but for printing).

Also how can I keep this macro separate from the file so that I can use
it over and over without having to recreate it every time I want to use
it?


Thanks.

Ryan Benedict
 

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