1
votes

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")
1
Pleas try to use either .Windows(1).View.paste or .Windows(1).View.pastespecial .... instead of ...ExecuteMso.... Does it improve anything? But check it with DoEvents as well.Kazimierz Jawor
Thanks for the help. Using pastespecial, DoEvents and declaring my worksheet as an object seemed to do the trick!John
Sure, it's acceptable and just what I needed.. Although now I am stuck on another issue. The reason I was using .Application.CommandBars.ExecuteMso ("PasteSourceFormatting") was because it was keeping my source formatting. PasteSpecial doesn't seem to keep all of my chart objects' original formatting. Is there a way to call this so that it acts the same as ExecuteMso?John
Have you tried with all PasteSpecial parameters, like ppPasteShape, ppPasteBitmap or ppPasteDefault or others?Kazimierz Jawor
After a lot of testing different solutions - Using the Wait(1) command between copying and pasting was actually the solution. I was able to use ExecuteMso or view.pastespecialJohn

1 Answers

0
votes

After a lot of testing different solutions - Using the Wait(1) command between copying and pasting was actually the solution.