• VBA PasteSpecial HTML Into PowerPoint 2010

    Author
    Topic
    #475459

    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!

    Viewing 6 reply threads
    Author
    Replies
    • #1271819

      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?

      • #1271820

        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!

    • #1271862

      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.

      27570-PPMacro

      • #1271917

        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.

        27570-PPMacro

        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?

    • #1271923

      Sorry, but I don’t know anything about Powerpoint VBA at all.
      Does this Microsoft article help?
      or this ?

      • #1272094

        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.

    • #1271926

      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)

      • #1272095

        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!

    • #1272153

      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”)

      • #1272211

        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!

        • #1294689

          Yes, that does seem to work beautifully in PPT 2010, but unfortunately I must support earlier versions as well — up to 2003.

          You seem to have some ambition. Try this.

          Since you have 2003, record the macro in PowerPoint ’03 and edit the code to give your project in the newer versions as good start.

          I hope you’ve already figured it out, but hopefully this will help someone else.

    • #1272233

      Where are you copying the original text from, another presentation or somewhere else?

      • #1272242

        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?

    • #1272329

      If I could suggest another approach -why not copy paste as a picture. this might give you better fidelity.

      • #1272422

        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!

    Viewing 6 reply threads
    Reply To: VBA PasteSpecial HTML Into PowerPoint 2010

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: