|
-
Jun 13th, 2006, 07:49 AM
#1
Thread Starter
New Member
Applying changes to all slides in Powerpoint
I searched for this but no luck. Total noob at writing macros and VB programming.
I created a simple little macro in Powerpoint 2003 - all it does is to remove the border around an imported image - i.e., right-click -> Format Autoshape -> Line Color -> No line:
VB Code:
Attribute VB_Name = "Module1"
Sub Macro1()
Attribute Macro1.VB_Description = "Macro recorded"
'
' Macro recorded
'
ActiveWindow.Selection.SlideRange.Shapes("Rectangle 3").Select
With ActiveWindow.Selection.ShapeRange
.Fill.Transparency = 0#
.Line.Visible = msoFalse
End With
End Sub
This macro works fine when executed on a slide. I'd like to change it now to have it run through all the slides in the presentation. I've been playing around with various options, reading VB help, etc., but no luck.
-
Jun 13th, 2006, 03:16 PM
#2
Re: Applying changes to all slides in Powerpoint
Welcome to the forums!
Here's the code that will remove all borders from the active presentation.
VB Code:
Sub RemoveBorders()
Dim oMySlide As Slide
Dim oMyShape As Shape
'Loop Thru all Slides
For Each oMySlide In ActivePresentation.Slides
'Loop through all shapes on the current slide
For Each oMyShape In oMySlide.Shapes
'Make the border invisible
oMyShape.Line.Visible = msoFalse
'Move to the next Shape
Next oMyShape
'Move to the Slide
Next oMySlide
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jun 13th, 2006, 03:59 PM
#3
Thread Starter
New Member
Re: Applying changes to all slides in Powerpoint
Thanks - this worked great! 
As a rule, do you typically create codes from scratch for functions like this? Because your code looks nothing like the macro created by Powerpoint. I thought a good way to start would be to have Powerpoint create the basic macro for one slide and then I wrap a loop around it to apply to all slides. But that seems more difficult - your code seems simpler and more intuitive.
-
Jun 13th, 2006, 04:04 PM
#4
Re: Applying changes to all slides in Powerpoint
AS a beginner, always record a simple version of your code before you start writing.
This will show you the objects, methods and properties that are being used.
That's about all that recorded macros are good for. They will never give you control structures like FOR..NEXT loops or IF..THEN..ELSE branching. This is where you need to write your own code, but the objects, methods and properties from the recorded macro will definetly help with this step.
Also, recorded macros will use lots of "Select", "Activate" and "Selection". All of these should be avoided as much as possible in your code, you very rarely need them.
Good luck and good coding! (And stop back in here if you need any more help)
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jun 13th, 2006, 05:46 PM
#5
Thread Starter
New Member
Re: Applying changes to all slides in Powerpoint
 Originally Posted by DKenny
Also, recorded macros will use lots of "Select", "Activate" and "Selection". All of these should be avoided as much as possible in your code, you very rarely need them.
Good point.
But now, suppose I want to modify your code so that instead of removing the border on all the shapes, I want to replace that loop with code that just removes the border on the shape identified by "Rectangle 3"
I tried to do this, but it didn't work right. I thought that would be pretty simple. What do I need to change? I was trying to define oMyShape to be that one shape rather than looping through all of them.
-
Jun 13th, 2006, 05:54 PM
#6
Re: Applying changes to all slides in Powerpoint
You will need to include an IF...THEN code block to examine the .name property of the oMyShape Object. This assumes that the shape is "Rectangle 3" on every sheet.
VB Code:
Sub RemoveBorders()
Dim oMySlide As Slide
Dim oMyShape As Shape
'Loop Thru all Slides
For Each oMySlide In ActivePresentation.Slides
'Loop through all shapes on the current slide
For Each oMyShape In oMySlide.Shapes
'Only continue if the shape is called "Rectangle 3"
If oMyShape.Name = "Rectangle 3" Then
'Make the border invisible
oMyShape.Line.Visible = msoFalse
End If
'Move to the next Shape
Next oMyShape
'Move to the Slide
Next oMySlide
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jun 13th, 2006, 07:11 PM
#7
Thread Starter
New Member
Re: Applying changes to all slides in Powerpoint
Oh, okay. I was trying to skip the looping of all shapes by directly defining the oMyShape as Rectangle 3. I just tried out this change and it works great.
Thanks for the help in coding!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|