Consulting

Results 1 to 6 of 6

Thread: Shape duplication and alignment

  1. #1

    Shape duplication and alignment

    Hi Everyone,

    I’ve created the macro the purpose of which is to duplicate selected shape and then transform it into small red box. However, I would like to enhance it a little bit by aligning two boxes - it would be great to have the small red box always in the bottom left corner of initially selected shape. Is it possible to have all of this in one macro?

    Sub DuplicateBox()
    Dim osld As Slide
    Dim oshp As Shape
    Set oshp = ActiveWindow.Selection.ShapeRange(1)
    oshp.Select
    With oshp.Duplicate
    .Fill.ForeColor.RGB = RGB(204, 0, 0)
    .Line.Visible = False
    .Width = 5.6692913386
    .Height = 5.6692913386

    End With
    End Sub

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Maybe this is what you mean. You probably need to explain why you chose the strange size for the red box. 7.2 would be 0.1 inch.

    Sub DuplicateBox()
    Dim oshp As Shape
    on error resume next
    Set oshp = ActiveWindow.Selection.ShapeRange(1)
    if not oshp is nothing then
    With oshp.Duplicate
    .Fill.ForeColor.RGB = RGB(204, 0, 0)
    .Line.Visible = False
    .Width = 5.6692913386
    .Height = 5.6692913386
    .Left = oshp.Left + oshp.Width - .Width
    .Top = oshp.Top + oshp.Height - .Height
    End With
    end if
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Sometimes I still feel like a beginner, and I'm definitely not a world class coder, so one of those may correct me, if this one's not good enough:

    Sub DuplicateBox()
    Dim osld As Slide
    Dim oshp As Shape
    
    On Error GoTo err
    
    Set oshp = ActiveWindow.Selection.ShapeRange(1)
    With oshp.Duplicate
     .Fill.ForeColor.RGB = RGB(204, 0, 0)
     .Line.Visible = False
     .Width = 5.6692913386
     .Height = 5.6692913386
     .Left = oshp.Left
     .Top = (oshp.Top + oshp.Height) - 5.6692913386
    End With
    Exit Sub
     
    err:
        MsgBox "Please select a shape"
    End Sub

  4. #4
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Oh, John was quicker. He's the expert, so take his version.

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Except my original code is bottom Right corner (i misread it) Mr German's code work just fine

    Sub DuplicateBox() 
    Dim oshp As Shape 
    Set oshp = ActiveWindow.Selection.ShapeRange(1) 
    
    With oshp.Duplicate 
    .Fill.ForeColor.RGB = RGB(204, 0, 0) 
    .Line.Visible = False 
    .Width = 5.6692913386 
    .Height = 5.6692913386 
    .Left = oshp.Left 
    .Top = oshp.Top + oshp.Height - .Height 
    End With 
    
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    Thank you guys for your help, both macros work just perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •