I am creating a powerpoint presentation out of an excel document. As I create each slide, I am copying a chart object from a worksheet in the excel document. The charts are not being copied after the first one. If I include a message box after each chart, they are. I've tried including a delay between these copy/pastes as well as DoEvents and messed around with trying to clear the clipboard after each paste but nothing seems to be working. I'm wondering if somebody can enlighten me to why this is happening? I am using Excel 2010/PP 2010 - This is basically the same code I'm using for each slide..
'Slide #5
Set PPSlide = PPPres.Slides.Add(5, ppLayoutTitleOnly)
Set ttlBox = PPSlide.Shapes("Title 1")
Worksheets("worksheetname").ChartObjects("Chart 2").Chart.ChartArea.Copy
With PPPres
.Windows(1).Activate
.Windows(1).View.GotoSlide 5
.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
End With
With PPSlide
.Shapes.AddPicture Filename:=imagePath & "outlier.png", LinktoFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=0, Top:=0
End With
With ttlBox
.Fill.ForeColor.RGB = RGB(0, 0, 128)
.Top = 0
.Left = 175
.Width = 545
.Height = 70
.TextFrame2.TextRange.Characters.Text = "Losses"
.TextFrame2.TextRange.Font.Size = "22"
.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = RGB(255, 255, 255)
.TextFrame2.AutoSize = msoAutoSizeTextToFitShape
End With
MsgBox ("Hi")
.Windows(1).View.paste
or.Windows(1).View.pastespecial ....
instead of...ExecuteMso...
. Does it improve anything? But check it withDoEvents
as well. – Kazimierz JaworppPasteShape
,ppPasteBitmap
orppPasteDefault
or others? – Kazimierz Jawor