Copy and paste PPT

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have thsi code and it is perfect insted of picture is it a way that the code is to delete microsoft object and paste microsoft objevt,

but is there a way that insted of picture but
Rich (BB code):
Sheets("Region").Select
    ActiveSheet.Shapes.Range(Array("Group 1a")).Select
    Selection.Copy
    'Set rng = ThisWorkbook.Sheets("Region").Range("A1:U37")
    
    Set mySlide = oPP.Slides(6)
    
    
    'Delete picture  insted microsoft object 
    Dim p As Long
    For p = mySlide.Shapes.Count To 1 Step -1
    Set PPShape = mySlide.Shapes(p)
    If PPShape.Type = msoPicture Then PPShape.Delete  
    Next
    
    
    'rng.Copy
    'mySlide.Shapes.PasteSpecial (ppPastePicture)
    mySlide.Shapes.PasteSpecial (ppPasteBitmap)  'insted microsoft object
    Set myShapeRange = mySlide.Shapes(mySlide.Shapes.Count)
        myShapeRange.LockAspectRatio = msoFalse
        myShapeRange.Left = 10
        myShapeRange.Top = 60
        myShapeRange.Height = 380   '380
        myShapeRange.Width = 495    '475
    Application.CutCopyMode = False
    
    oPP.Save
    oPP.Close
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What type of object do you have?

It looks like you may have groups of some sort. If this is the case, you can delete your groups as follows...

VBA Code:
If PPShape.Type = msoGroup Then PPShape.Delete

And to paste your group...

VBA Code:
mySlide.Shapes.PasteSpecial ppPasteShape

Hope this helps!
 
Last edited:
Upvote 0
What type of object do you have?

It looks like you may have groups of some sort. If this is the case, you can delete your groups as follows...

VBA Code:
If PPShape.Type = msoGroup Then PPShape.Delete

And to paste your group...

VBA Code:
mySlide.Shapes.PasteSpecial ppPasteShape

Hope this helps!
I tried but getting this error

1694939609537.png
 
Upvote 0
You've declared your loop variable p as a Shape, yet you're assigning it a number. Hence the type mismatch error. You should declare it as Long...

VBA Code:
Dim p as Long
 
Upvote 0
this is the entire code, still delete is not working.

VBA Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Copy pasting the Map in PPT slides all 2
'
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


    Dim mySlide As PowerPoint.Slide
    Dim myShapeRange As PowerPoint.Shape
    
    Dim oPA As PowerPoint.Application
    Dim oPP As PowerPoint.Presentation
    Dim oPS As PowerPoint.SlideRange
    Dim strTemplate As String
    Dim rng As Range
    Dim Fname As String
        
    Fpath = ActiveWorkbook.Path
    
    strTemplate = Fpath & "\" & "Fixed Weekly Report - Master1.pptx"      ''"C:\Viral Shah\Automation\Weekly Report\Fixed Weekly Report.pptx"
    
    Set oPA = New PowerPoint.Application
    oPA.Visible = msoTrue
    'changed this line to assign the new presentation to your variable
    'Set oPP = oPA.Presentations.Open(strTemplate, untitled:=msoTrue)
    Set oPP = oPA.Presentations.Open(strTemplate)
        
    'If Not oPS Is Nothing Then Set oPS = Nothing
    'If Not oPP Is Nothing Then Set oPP = Nothing
    'If Not oPA Is Nothing Then Set oPA = Nothing
    
Err_PPT:
    If Err <> 0 Then
    MsgBox Err.Description
    Err.Clear
    Resume Next
    End If
    
    
    Sheets("OLTFinal Report").Select
    ActiveSheet.Shapes.Range(Array("Group 15a")).Select
    Selection.Copy
    'Set rng = ThisWorkbook.Sheets("Region").Range("A1:U37")
    
    Set mySlide = oPP.Slides(2)
    
    
    'Delete picture
    Dim p As Long
    For p = mySlide.Shapes.Count To 1 Step -1
    Set PPShape = mySlide.Shapes(p)
    'If PPShape.Type = Shape Then PPShape.Delete
    If PPShape.Type = msoPicture Then PPShape.Delete
    Next
    
    
    'rng.Copy
    'mySlide.Shapes.PasteSpecial (ppPastePicture)
    
    'mySlide.Shapes.PasteSpecial ppPasteOLEObject, msoCTrue
    mySlide.Shapes.PasteSpecial ppPasteShape
    'mySlide.Shapes.PasteSpecial (ppPasteBitmap)
'    Set myShapeRange(1) = mySlide.Shapes(mySlide.Shapes.Count)
'        myShapeRange(1).LockAspectRatio = msoFalse
'        myShapeRange(1).Left = 10
'        myShapeRange(1).Top = 60
'        myShapeRange(1).Height = 380   '380
'        myShapeRange(1).Width = 495    '475
    Application.CutCopyMode = False
    
'    oPP.Save
'    oPP.Close
    
End Sub
 
Upvote 0
As per my previous suggestion, try replacing...

VBA Code:
If PPShape.Type = msoPictureThen PPShape.Delete

with

VBA Code:
If PPShape.Type = msoGroup Then PPShape.Delete

If this still doesn't help, please confirm which type of object you have.
 
Upvote 0
Solution
one qurierie

I am not able to do the left and top positions


VBA Code:
mySlide.Shapes.PasteSpecial ppPasteShape  [B]' here the code ends its not executiong left and top positions[/B]
    'mySlide.Shapes.PasteSpecial (ppPasteBitmap)
    Set myShapeRange = mySlide.Shapes(mySlide.Shapes.Count)
        myShapeRange.LockAspectRatio = msoFalse
        myShapeRange.Left = 5
        myShapeRange.Top = 30
'        myShapeRange(1).Height = 380   '380
'        myShapeRange(1).Width = 495    '475
 
Upvote 0
ActiveSheet.Shapes.Range(Array("Group 15a")).Select
First, can you please confirm the type of object that the above line refers to? Also, it might help if you temporary removed the error handling from your code and run it again. This time when the error occurs your code should break and you should receive an error message. Can you tell us which error you're receiving and confirm which line is causing the error?
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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