VBA: “Can't find project or library” when using PasteSpecial

Lannheday

New Member
Joined
Oct 28, 2015
Messages
2
Hello,

I'm trying to copy charts from an Excel workbook to placeholders in a Powerpoint presentation. Below are the codes I'm using:

Code:
<code>Sub Pwp()
   Dim wb As Workbook
   Dim ppt As PowerPoint.Presentation
   Dim pptApp As PowerPoint.Application
   Dim sld As PowerPoint.Slide
   Dim shp As PowerPoint.Shape
   Dim pth As String
   Dim i As Long

   Set wb = ActiveWorkbook
   pth = wb.path & "\My Presentation.pptm"
   Set pptApp = New PowerPoint.Application
   pptApp.Visible = True
   pptApp.Presentations.Open Filename:=pth
   Set ppt = pptApp.ActivePresentation

   For Each sld In ppt.Slides
       i = sld.SlideNumber
       sld.Select
       For Each shp In sld.Shapes
           If i = 2 And shp.ID = 6148 Then
                shp.TextFrame.TextRange.Text = ""
                wb.Activate
                Sheets(1).ChartObjects("From2007").Chart.ChartArea.Copy
                pptApp.Activate
                shp.Select msoCTrue
                ppt.Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
           End If
       Next shp
   Next sld
End Sub</code>

I got the error with the
Code:
ppPasteMetafilePicture
, saying "Can't find project or library". If I remove it, putting only
Code:
PasteSpecial
, then the code works but I cannot keep the format of the chart since my Powerpoint presentation uses a theme.


Could anyone help me get rid of this error?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hello mole999,

Thanks for your reply. Actually I found the reason: in my computer there are many versions of MS Office, so I have to use Powerpoint.ppPasteMetafilePicture.

The site you gave is a very good resource though.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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