Problem Copying Charts to PowerPoint

S

Stratuser

I have some Excel code that copies some Excel charts to PowerPoint. It's
giving me an error message that the clipboard is empty. Something in my code
must be emptying the clipboard, but I don't see what it is. The error
message occurs when I try to paste the chart at the last line of the code
shown below:

Range("Analysis_Left").CopyPicture Appearance:=xlScreen, Format:=xlPicture

'Open PowerPoint
Set myAPP = CreateObject("Powerpoint.Application")
myAPP.Visible = True
myAPP.WindowState = ppWindowMinimized
ThisWorkbook.Activate

'Create one new PowerPoint presentation and no more
If myAPP.Presentations.Count = 0 Then
Set ppPres = myAPP.Presentations.Add(msoTrue)
ppPres.Slides.Add 1, ppLayoutBlank

Else
NextSlide = 1 + (myAPP.ActivePresentation.Slides.Count)
myAPP.ActiveWindow.View.GotoSlide
Index:=myAPP.ActivePresentation.Slides.Add(NextSlide,
Layout:=ppLayoutBlank).SlideIndex

End If

'Paste the left side of the image into a PowerPoint slide
myAPP.ActiveWindow.View.Paste
 
J

joel

Why not move the copypicture to the end of the macro. You may want t
change activesheet to sheets("Sheet1").



'Open PowerPoint
Set myAPP = CreateObject("Powerpoint.Application")
myAPP.Visible = True
myAPP.WindowState = ppWindowMinimized
ThisWorkbook.Activate

'Create one new PowerPoint presentation and no more
If myAPP.Presentations.Count = 0 Then
Set ppPres = myAPP.Presentations.Add(msoTrue)
ppPres.Slides.Add 1, ppLayoutBlank

Else
NextSlide = 1 + (myAPP.ActivePresentation.Slides.Count)
myAPP.ActiveWindow.View.GotoSlide
Index:=myAPP.ActivePresentation.Slides.Add(NextSlide,
Layout:=ppLayoutBlank).SlideIndex

End If

'Paste the left side of the image into a PowerPoint slide
thisworkbook.activesheet.Range("Analysis_Left").CopyPictur
Appearance:=xlScreen, Format:=xlPicture

myAPP.ActiveWindow.View.Paste
 
S

Stratuser

Thanks, I tried both of those things, and neither one has any effect.

I should have been more specific. The code works the first time I run it,
and also if I run it over and over, but if I click on the PowerPoint file and
go back to Excel and run the code again, then it doesn't work and I get the
error message that says the clipboard is empty. However, the clipboard can't
be empty because I can then manually paste from it straight into the
PowerPoint file. Somehow, by going into the PowerPoint file after the code
runs I am disrupting something.
 
J

joel

I think I found the problem. Your slide count is wrong. When yo
create a new presentation it automatically creates a presentation wit
one slide. So when you add a slide you have two slides. The number o
slides is always one created than your slide count

When you already have a presentation your slide count equals the numbe
of slides.

I remove the add slide from the case where you don't have
presentation. then I removed the add 1 from the Next slide count.


'Open PowerPoint
Set myAPP = CreateObject("Powerpoint.Application")
myAPP.Visible = True
myAPP.WindowState = ppWindowMinimized
ThisWorkbook.Activate

'Create one new PowerPoint presentation and no more
If myAPP.Presentations.Count = 0 Then
Set ppPres = myAPP.Presentations.Add(msoTrue)

Else
NextSlide = myAPP.ActivePresentation.Slides.Count
myAPP.ActiveWindow.View.GotoSlide
Index:=myAPP.ActivePresentation.Slides.Add(NextSlide,
Layout:=ppLayoutBlank).SlideIndex

End If

'Paste the left side of the image into a PowerPoint slide
thisworkbook.activesheet.Range("Analysis_Left").CopyPictur
Appearance:=xlScreen, Format:=xlPicture

myAPP.ActiveWindow.View.Paste
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top