Consulting

Results 1 to 2 of 2

Thread: Merge two shape using vba

  1. #1

    Merge two shape using vba

    Sir,


    I am a newbie in PowerPoint vba.It may be super simple question for other but I can not configure it.
    I want to merge two shape by subtract using vba.
    I find a solution from searching web but how to rename this new generated shape/make a shape object.

    I want to rename it "MergeShape"


    Any solution will be appreciated.


    Sub mergeShape()
    Dim shp1 As Shape
    Dim shp2 As Shape
    Dim shp3 As Shape
    Set shp1 = ActivePresentation.Slides(1).Shapes("Rectangle1")
    Set shp2 = ActivePresentation.Slides(1).Shapes("Pentagon1")
    Call ActiveWindow.Selection.SlideRange(1).Shapes.Range(Array(shp1.ZOrderPosition, shp2.ZOrderPosition)).MergeShapes(msoMergeSubtract, shp1)
    End Sub

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,043
    Location
    MergeShapes returns VOID so iot is difficult to refer to the new shape. However in most cases it will have the zorder position one less than the first shape so this MIGHT work

    Sub mergeShape()
    Dim shp1 As Shape
    Dim shp2 As Shape
    Dim shp3 As Shape
    Dim osld As Slide
    Dim lngPos As Long
    Set osld = ActivePresentation.Slides(1)
    Set shp1 = osld.Shapes("Rectangle1")
    lngPos = shp1.ZOrderPosition
    Set shp2 = osld.Shapes("Pentagon1")
    Call osld.Shapes.Range(Array(shp1.ZOrderPosition, shp2.ZOrderPosition)).MergeShapes(msoMergeSubtract, shp1)
    osld.Shapes(lngPos - 1).Name = "merged"
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

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