how to delay Past until complete merge shapes

Dossfm0q

Banned User
Joined
Mar 9, 2009
Messages
570
Office Version
  1. 2019
Platform
  1. Windows
Greetings
1-How delay paste until merge shapes function in red color
2- it is work well if remove pptApp.Quit ' close Power Point
3- to declare Sld as object to avoid select Microsoft Power point Reference

Code:
Sub CombineShapes()
    
Dim WB As Workbook
Dim WS As Worksheet
Dim Shp As Shape, Rctangl As Shape, Ovl As Shape
Dim Names(1 To 2) As Variant
Set WB = ThisWorkbook 'Set WB = Workbooks("WorkbookName")
Set WS = WB.ActiveSheet 'Set WS = WB.WorkSheets("WorkSheetName")


With WS
    For Each Shp In .Shapes
        Shp.Delete
    Next
    
   ' Add Shape
    Set Rctngl = WS.Shapes.AddShape(msoShapeRectangle, 100, 100, 125, 200)
        With Rctngl
            .Name = "MyRectangle"
            Names(1) = .Name
        End With
    
   ' Add Hole
    Set Ovl = WS.Shapes.AddShape(msoShapeOval, Rctngl.Left + (Rctngl.Width * 0.5) - 15, Rctngl.Top + 15, 30, 30)
        With Ovl
            .Name = "Oval"
            Names(2) = .Name


        End With
         
    With .Shapes.Range(Names)
    
    .Select
    End With
    
    Selection.Cut
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 Merge_Shapes ''''' go to Power Point to merge shapes
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
[COLOR=#ff0000]
[/COLOR]
[SIZE=2][B][COLOR=#ff0000].Paste ''' how to delay Paste untill Merge_Shapes complete and cut then Paste[/COLOR][/B][/SIZE]
End With 'WS


End Sub
Public Function Merge_Shapes()


Dim pptApp As Object
Dim pptPres As Object
[B][COLOR=#ff0000]Dim Sld As slide[/COLOR][/B]
Dim Visibility As Boolean
'Visibility = msoFalse ' To   pptApp Hide
Visibility = msoTrue ' to appear pptApp
    
    On Error Resume Next
        Set pptApp = Nothing
        Set pptApp = CreateObject("Powerpoint.Application")
        
        pptApp.Visible = Visibility ' To pptApp Hide
        If Visibility = msoTrue Then pptApp.Activate ' To pptApp Hide
        
        Set pptPres = pptApp.Presentations.Add(WithWindow:=Visibility) ' To keep pptApp Hide
        Set pptLayout = pptPres.Designs(1).SlideMaster.CustomLayouts(7)
        Set Sld = pptPres.Slides.AddSlide(1, pptLayout)
        pptApp.Visible = msoFalse
    
    On Error GoTo 0
    
        With Sld
                .Shapes.Paste '.Select 'for PowerPoint dot Shapes dot Paste
        
                .Shapes.Range(Array("MyRectangle", "Oval")).Select  '.MergeShapes (msoMergeCombine)
                .Shapes.Range(Array("MyRectangle", "Oval")).MergeShapes (msoMergeCombine)
        
                .Shapes(.Shapes.Count).Cut ' cut to be pasteed on Excel
        End With


[COLOR=#ff0000] pptApp.Quit ' close Power Point[/COLOR]




Set Sld = Nothing
Set pptPres = Nothing
Set pptApp = Nothing


End Function
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try this:

Code:
    Selection.Cut
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Merge_Shapes ''''' go to Power Point to merge shapes
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
[COLOR=#0000cd]    DoEvents[/COLOR]
[COLOR=#0000cd]    Application.Wait (Now + TimeValue("00:00:05")) 'delay 5 seconds[/COLOR]
[COLOR=#0000cd]    DoEvents[/COLOR]
    
    .Paste ''' how to delay Paste untill Merge_Shapes complete and cut then Paste
 
Upvote 0
Thanks sir and now wors with declare Sld as object By
Replacing: '.Shapes.Range(Array("MyRectangle", "Oval")).MergeShapes (msoMergeCombine)
with: pptApp.CommandBars.ExecuteMso ("ShapesCombine")




Code:
Sub CombineShapes()


Dim WB As Workbook
Dim WS As Worksheet
Dim Shp As Shape, Rctangl As Shape, Ovl As Shape, MergeShape As Shape
Dim Shps As Variant
Dim Names(1 To 2) As Variant
Set WB = ThisWorkbook 'Set WB = Workbooks("WorkbookName")
Set WS = WB.ActiveSheet 'Set WS = WB.WorkSheets("WorkSheetName")


With WS
    For Each Shp In .Shapes
        Shp.Delete
    Next
    
   ' Add Shape
    Set Rctngl = WS.Shapes.AddShape(msoShapeRectangle, 100, 100, 125, 200)
        With Rctngl
            .Name = "MyRectangle"
            Names(1) = .Name
            Lft = .Left
            Tp = .Top
            
        End With
   ' Add Hole
    Set Ovl = WS.Shapes.AddShape(msoShapeOval, Rctngl.Left + (Rctngl.Width * 0.5) - 15, Rctngl.Top + 15, 30, 30)
        With Ovl
            .Name = "Oval"
            Names(2) = .Name


        End With
     Set Shps = .Shapes.Range(Names)
    With Shps '.Shapes.Range(Names)
    
    .Select
    End With
    
    Selection.Cut
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
     Merge_Shapes.Cut ''''' go to Power Point to merge shapes
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


    DoEvents
    Application.Wait (Now + TimeValue("00:00:05")) 'delay 5 seconds
    DoEvents
 
    .Paste
        Set MergeShape = .Shapes(.Shapes.Count) ''' how to delay Paste untill Merge_Shapes complete and cut then Paste
            With MergeShape
            .Left = Lft
            .Top = Tp
                    With .Line
                    .ForeColor.RGB = RGB(255, 0, 0)
                    .Weight = 3
                    End With
                    With .Fill
                    .ForeColor.RGB = RGB(255, 255, 0)
                    End With
            End With


End With 'WS


 
End Sub
Public Function Merge_Shapes() As Object


Dim pptApp As Object
Dim pptPres As Object
Dim Sld As Object
Dim Visibility As Boolean
'Visibility = msoFalse ' To   pptApp Hide
Visibility = msoTrue ' to appear pptApp
    
    On Error Resume Next
        Set pptApp = Nothing
        Set pptApp = CreateObject("Powerpoint.Application")
        
        pptApp.Visible = Visibility ' To pptApp Hide
        If Visibility = msoTrue Then pptApp.Activate ' To pptApp Hide
        
        Set pptPres = pptApp.Presentations.Add(WithWindow:=Visibility) ' To keep pptApp Hide
        Set pptLayout = pptPres.Designs(1).SlideMaster.CustomLayouts(7)
        Set Sld = pptPres.Slides.AddSlide(1, pptLayout)
        pptApp.Visible = msoFalse
    
    On Error GoTo 0
    
        With Sld
                .Shapes.Paste '.Select 'for PowerPoint dot Shapes dot Paste
        
                .Shapes.Range(Array("MyRectangle", "Oval")).Select
                pptApp.CommandBars.ExecuteMso ("ShapesCombine")
                '.Shapes.Range(Array("MyRectangle", "Oval")).MergeShapes (msoMergeCombine)
        
            Set Merge_Shapes = .Shapes(.Shapes.Count)   ' cut to be pasteed on Excel
        End With


  pptApp.Quit ' close Power Point




Set Sld = Nothing
Set pptPres = Nothing
Set pptApp = Nothing


End Function
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top