Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Star Lounger
    Join Date
    Sep 2006
    Location
    New York, New York, USA
    Posts
    76
    Thanks
    1
    Thanked 0 Times in 0 Posts

    VBA PasteSpecial HTML Into PowerPoint 2010

    Hi,

    I am a PowerPoint newbie. I want to programmatically paste some HTML stored on the Windows Clipboard into a PowerPoint slide. Nothing fancy, just some simple marked-up text (italics, bold, etc.) and possibly pictures into a blank slide. I already have the code working to paste the HTML onto the Clipboard, just can't see how to paste it into the slide. I wanted to record a macro to learn how PPT would do this, but can't see how to do that, like in Word or Excel.

    Any ideas are most appreciated!

  2. #2
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts
    I'm not in front of 2010 right now. But I am curious as to why you wish to do this? Can you expand on your scenario?
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  3. #3
    Star Lounger
    Join Date
    Sep 2006
    Location
    New York, New York, USA
    Posts
    76
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Certainly. I have an application (VB6) that allows the user to export content to various applications, including PowerPoint. So, if they have some HTML content that they want to include in their own PowerPoint presentation (e.g. outside of the scope of my application), I want to provide an easy copy/paste function to do this for them.

    Does this explanation provide enough information?

    Thanks!

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    The Help for Powerpoint 2010 says that the Macro Recorder is no longer available. Instead you have to write the code yourself. To be able to do that you need to display the Developer Tab on the Ribbon.
    File...Options..Customize Ribbon. Tick the checkbox for Developer.

    PPMacro.gif
    Regards
    John



  5. #5
    Star Lounger
    Join Date
    Sep 2006
    Location
    New York, New York, USA
    Posts
    76
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by johnhutchison View Post
    The Help for Powerpoint 2010 says that the Macro Recorder is no longer available. Instead you have to write the code yourself. To be able to do that you need to display the Developer Tab on the Ribbon.
    File...Options..Customize Ribbon. Tick the checkbox for Developer.

    PPMacro.gif
    Thanks, John. I do know that the recorder is no longer available, that's my big problem. I could have recorded it and at least seen what the object model objects were that I needed to manipulate. I can do this easily in Word, but am completely dumbfounded how to do this in PPT. I even tried it in PPT 2003 to see what the recorded macro looked like, but it didn't record the PasteSpecial paste that I did!

    Any ideas how to do a PasteSpecial in PPT VBA?

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Sorry, but I don't know anything about Powerpoint VBA at all.
    Does this Microsoft article help?
    or this ?
    Regards
    John



  7. #7
    3 Star Lounger
    Join Date
    Feb 2007
    Location
    Durham, Durham, United Kingdom
    Posts
    286
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Can you actually do this manually? I don't think it's possible to paste as HTML in PowerPoint.

    If it was it would look like this

    Dim osld As Slide
    Set osld = ActiveWindow.Slides(3) ' change as needed
    osld.Shapes.PasteSpecial (ppPasteHTML)

  8. #8
    Star Lounger
    Join Date
    Sep 2006
    Location
    New York, New York, USA
    Posts
    76
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by johnhutchison View Post
    Sorry, but I don't know anything about Powerpoint VBA at all.
    Does this Microsoft article help?
    or this ?
    Thanks, John. They were a bit helpful, at least in understanding the object model a bit better.

  9. #9
    Star Lounger
    Join Date
    Sep 2006
    Location
    New York, New York, USA
    Posts
    76
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JohnWilson View Post
    Can you actually do this manually? I don't think it's possible to paste as HTML in PowerPoint.

    If it was it would look like this

    Dim osld As Slide
    Set osld = ActiveWindow.Slides(3) ' change as needed
    osld.Shapes.PasteSpecial (ppPasteHTML)
    I'm not sure. As I said, I am a PPT newbie, more familiar with Word and Excel. Word seems much more flexible, which I suppose is to be expected. The fact that there is an enumeration available to specify a HTML paste seems to indicate that it is possible, but nothing surprises me with Microsoft.

    I was able to get a reasonable result for what I am doing, although still not pasting strictly as HTML.

    btw, would you happen to know how I can paste the content into PPT while preserving the source fonts? It looks like PPT enforces its own fonts -- I guess from the SlideMaster or some such nuisance! Basically, when I paste in the content it might have a few different fonts, point sizes, etc. It looks like PPT preserves markup like bold, italics, etc., but not the fonts. Any ideas?

    Thanks again for the help!

  10. #10
    3 Star Lounger
    Join Date
    Feb 2007
    Location
    Durham, Durham, United Kingdom
    Posts
    286
    Thanks
    0
    Thanked 10 Times in 10 Posts
    You could try this (NOTE it is 2010 specific - it won't work in earlier versions)

    ActiveWindow.View.GotoSlide 3 ' obviously change as required
    CommandBars.ExecuteMso ("PasteSourceFormatting")

  11. #11
    Star Lounger
    Join Date
    Sep 2006
    Location
    New York, New York, USA
    Posts
    76
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JohnWilson View Post
    You could try this (NOTE it is 2010 specific - it won't work in earlier versions)

    ActiveWindow.View.GotoSlide 3 ' obviously change as required
    CommandBars.ExecuteMso ("PasteSourceFormatting")
    Yes, that does seem to work beautifully in PPT 2010, but unfortunately I must support earlier versions as well -- up to 2003.

    I shall crack on looking for a similar solution. Thanks for the help!

  12. #12
    3 Star Lounger
    Join Date
    Feb 2007
    Location
    Durham, Durham, United Kingdom
    Posts
    286
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Where are you copying the original text from, another presentation or somewhere else?

  13. #13
    Star Lounger
    Join Date
    Sep 2006
    Location
    New York, New York, USA
    Posts
    76
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JohnWilson View Post
    Where are you copying the original text from, another presentation or somewhere else?
    It is copied to the Clipboard from the WebBrowser control (hence my original desire to paste as HTML). The app then instantiates PPT and pastes the content into the slide -- no shapes of any kind, just a blank slide. I want to preserve the content's formatting - font, point size, bold/italic/underline, etc. - as closely as possible.

    I also noticed when using your suggestion about ExecuteMso that the pasted content appeared in a shape that was about halfway vertically down the slide, as opposed to a straight pastespecial where it appeared properly centered on the slide. What am I missing?

  14. #14
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts
    If I could suggest another approach -why not copy paste as a picture. this might give you better fidelity.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  15. #15
    Star Lounger
    Join Date
    Sep 2006
    Location
    New York, New York, USA
    Posts
    76
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WebGenii View Post
    If I could suggest another approach -why not copy paste as a picture. this might give you better fidelity.
    Nice idea, and I did try that just to see if it would work, but unfortunately the resulting PPT content needs to be editable by the user. Sorry!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •