none
executemso pastesourceformatting works when "Step Into" not in macro excel powerpoint RRS feed

  • Question

  • Hi,

    I've written some code which I will paste below and I'm having an incredibly strange issue...

    I am copying and pasting from excel to powerpoint using commandbars.executemso("PasteSourceFormatting") to maintain the integrity of the appearance of the excel range (ppt as new Powerpoint.application, pptbb as presentation) :

    wbstocks.Sheets(secBook).Range(wbstocks.Sheets(secBook).Cells(1, 1), wbstocks.Sheets(secBook).Cells(X, 10)).Copy
          
            lastslide = pptbb.Slides.Count
            pptbb.Slides(lastslide).Select

    pptbb.Slides(lastslide).Application.Activate
            pptbb.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")

    ****

    When I set a breakpoint on pptbb.slides(lastslide).select and f8 to the next line, it pastes with the correct formatting.  When I run my program normally without the breakpoint, it pastes in the wrong format.  I have tried using application.wait in between the lines as well as a countdown timer with do events...Nothing seems to work other than a physical breakpoint and stepping through the next step. ppt.visible is set to msotrue

    Any help would be GREATLY GREATLY appreciated!

    Thanks,

    Matt

    Wednesday, October 8, 2014 10:28 PM

All replies

  • Try to use the PastSpecial property of Powerpoint instead:

    Dim mySlide As Powerpoint.Slide
    
    mySlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile

    Will that work for you?

    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.


    • Edited by danishani Wednesday, October 8, 2014 10:45 PM
    Wednesday, October 8, 2014 10:45 PM
  • Hi Daniel,

    Thanks for your response.  I had tried that, and it works, however there is a need to resize and the format of "PasteSourceFormatting" is far more preferable for what im doing.  The range I am pasting will be changing sizes which is why enhanced meta is complicated sometimes

    I mostly just cannot for the life of me figure out why it would be working in break mode and not when it's run even with waits etc.

    Wednesday, October 8, 2014 10:53 PM
  • Interesting, I have no problem to resize the Shape after I have paste into a PowerPoint Slide.
    I tried something like this:

    Dim mySlide As PowerPoint.Slide
    Dim myShapeRange As PowerPoint.Shape
    
      mySlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile
      Set myShapeRange = mySlide.Shapes(mySlide.Shapes.Count)
      
        'Set position and change height and width
          myShapeRange.Left = 100
          myShapeRange.Top = 100
          myShapeRange.Height = 200
          myShapeRange.Width = 400

    Not sure why your code does not work to be honest.

    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Wednesday, October 8, 2014 11:18 PM