Results 1 to 7 of 7

Thread: Applying changes to all slides in Powerpoint

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    Portland, OR, USA
    Posts
    4

    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:
    1. Attribute VB_Name = "Module1"
    2. Sub Macro1()
    3. Attribute Macro1.VB_Description = "Macro recorded"
    4. '
    5. ' Macro recorded
    6. '
    7.  
    8.     ActiveWindow.Selection.SlideRange.Shapes("Rectangle 3").Select
    9.     With ActiveWindow.Selection.ShapeRange
    10.         .Fill.Transparency = 0#
    11.         .Line.Visible = msoFalse
    12.     End With
    13. 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.

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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:
    1. Sub RemoveBorders()
    2. Dim oMySlide As Slide
    3. Dim oMyShape As Shape
    4.  
    5.     'Loop Thru all Slides
    6.     For Each oMySlide In ActivePresentation.Slides
    7.        
    8.         'Loop through all shapes on the current slide
    9.         For Each oMyShape In oMySlide.Shapes
    10.        
    11.             'Make the border invisible
    12.            oMyShape.Line.Visible = msoFalse
    13.        
    14.         'Move to the next Shape
    15.         Next oMyShape
    16.    
    17.     'Move to the Slide
    18.     Next oMySlide
    19.    
    20.  
    21. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    Portland, OR, USA
    Posts
    4

    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.

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    Portland, OR, USA
    Posts
    4

    Re: Applying changes to all slides in Powerpoint

    Quote 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.

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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:
    1. Sub RemoveBorders()
    2. Dim oMySlide As Slide
    3. Dim oMyShape As Shape
    4.  
    5.     'Loop Thru all Slides
    6.     For Each oMySlide In ActivePresentation.Slides
    7.        
    8.         'Loop through all shapes on the current slide
    9.         For Each oMyShape In oMySlide.Shapes
    10.            
    11.             'Only continue if the shape is called "Rectangle 3"
    12.             If oMyShape.Name = "Rectangle 3" Then
    13.                 'Make the border invisible
    14.                 oMyShape.Line.Visible = msoFalse
    15.             End If
    16.        
    17.         'Move to the next Shape
    18.         Next oMyShape
    19.    
    20.     'Move to the Slide
    21.     Next oMySlide
    22.    
    23. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    Portland, OR, USA
    Posts
    4

    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
  •  



Click Here to Expand Forum to Full Width