Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loading HTML intom a Word doc object (Word 2000, XP, and 2003)

    I have a requirement of using HTML for the contents of a Word document and then turn it into a DCO file. Currently I form the HTML content, save it as a file and then using Word object Add method to load it and then save it as a DOC. It seems I should be able to load thML content into a Word object such as the Add method and then juist save it as DOC. The first argument of the Add method appears to be an "Object Template" which suggests to me if I could cast the HTML that is in memory to an object then I could add it to a Document object and it would render it as Word. Anyway is there a way of taking HTML content and loading into Word so the textual content is as a Word document rather than just HTML without first having to save it as a HTML file?

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Loading HTML intom a Word doc object (Word 2000, XP, and 2003)

    I just tried typing
    <code>
    ActiveDocument.HTMLProject.HTMLProjectItems(1).Tex t = "<HTML><HEAD></HEAD><BODY>

    Stuart Was Here</BODY></HTML>"
    </code>
    into the VBE Immediate window, and the word user interface displayed a dialog box with "Refresh" and "Do not refresh" buttons, clicking the refresh button replaced the text of the current document with the text I had entered. You should be able to do something similar.

    StuartR

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Loading HTML intom a Word doc object (Word 200

    Documents.Open and then ActiveDocument.SaveAs seems simplest, but as you point out, the round trip to disk isn't very efficient.

    In addition to Stuart's suggestion, the Windows API lets you stuff content into the clipboard in your choice of formats. The MSKB has articles on how to put HTML onto the clipboard; I believe there is a VBA example in the context of MS Access. (I looked last weekend, so don't hold me to that!)

  4. #4
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loading HTML intom a Word doc object (Word 200

    Thank you both. I tried using the <Title> tag in the same HTML and then it only creates a blank document. If I remove the <Title> inculing the closing title tag trhen it works.

Posting Permissions

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