Rahul
Rahul

Reputation: 11560

Get formatted html from web to MS-Word

I have asked this question many time before with other questions. Never got answer.

Is there any way to get webdata with formatting and put it in microsoft word?

I got some solution based on this answer

HTML Text with tags to formatted text in an Excel cell

In My case I am getting data directly from web. Is there any direct process to get formatted HTML content.

My code is:

If .Hyperlinks.Count > 0 Then
    HttpReq.Open "GET", .Hyperlinks(1).Address, False
    HttpReq.send
    oHtml.body.innerHTML = HttpReq.responseText
    StrTxt = oHtml.getElementsByClassName("class").Item.innerHTML
        With IE
            .Visible = True
            .navigate "about:blank"
            .Document.body.innerHTML = StrTxt
            .Document.execCommand "SelectAll"
            .Document.execCommand "Copy"
        End With
    Set rng = Tbl.Cell(i, 1).Range
        rng.Collapse wdCollapseStart
        rng.PasteAndFormat wdPasteDefault
    Set rng = nothing
End If

Is there any better way of doing this?

Upvotes: 0

Views: 601

Answers (1)

Cindy Meister
Cindy Meister

Reputation: 25693

Since Word requires a converter to bring HTML into a Word document you basically have three choices:

  1. Use the Clipboard (copy, paste)
  2. Save the HTML as a file then use InsertFile
  3. Parse the HTML with your code and "translate" it to valid Word object model commands.

"Better" is a matter of opinion and depends on what you mean by "better". Simplest is certainly what you're doing...

Upvotes: 1

Related Questions