开发者

Open HTML file in excel, preserving HTML inline styling

I'm trying to open a HTML file in excel (from VBA) so that the HTML inline styling is preserved. Are there any special ways of doing this because currently I've tried creating the HTML as a string and inserting into a cell using ActiveSheet.Range("A10") = HTMLStr but this isn't working and also when I open the file in Excel usi开发者_Go百科ng:

Workbooks.Open

this also does not render the HTML correctly

(edit my final result is to turn the html into a pdf)


Why do you need to open the page in Excel - is it just so you can make a PDF (Excel 2007/10) ? You could try passing the HTML to IE and automating a copy/paste from there.

As an example, the following code will take a selection of cells with HTML, transfer each one to IE, then copy back the result.

Sub FormatHtmlViaIE()

Dim ie As Object, tr, c As Range

    Set ie = CreateObject("internetexplorer.application")
    With ie

        .Visible = True
        .Navigate "about:blank"
        Do While .busy
        Loop

        For Each c In Selection
            .document.body.innerHTML = c.Value
            .document.body.createtextrange.execCommand "Copy"
            Selection.Parent.Paste Destination:=c
        Next c

        .Quit

    End With

End Sub


Otherwise is open page in excel.

For Example

Sub OpenPage()
'officevb.com
Dim wb As Workbook

Set wb = Workbooks.Open("http://www.stackoverflow.com")

wb.SaveAs "c:\Your\Path\Here\NameOfFile", xlWorkbookDefault

End Sub

[]'s

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜