0

我正在寻找以下 VB 的解决方案来批处理 .html 文件/url。我想保存要在 Microsoft Word 中打开的 .html 文件。

这是我正在使用的代码,但我需要它来处理多个 .html 文件:

Option Explicit
'Just change these two lines
Const HTMLFileIn="http://www.example.com"   
Const DocFileOut="H:\Word"

Dim MyWord,oIE
Set MyWord=CreateObject("Word.Document") 
Set oIE=CreateObject("InternetExplorer.Application")
oIE.Navigate HTMLFileIn
Attend
oIE.document.body.createTextRange.execCommand("Copy")
Attend
MyWord.Content.Paste
MyWord.SaveAs DocFileOut
MyWord.Close
oIE.Quit
Set oIE=Nothing
Set MyWord=Nothing 
MsgBox HTMLFileIn & " is now saved as " & DocFileOut

Sub Attend
    Wscript.Sleep 500
    While oIE.busy
        Wscript.Sleep 1000
    Wend
    While oIE.Document.readyState <> "complete"
        Wscript.Sleep 1000
    Wend
End Sub
4

1 回答 1

0

尝试这个。(经过试验和测试

'~~> Replace this with the text file which has the links
Const hLinksFile As String = "C:\Temp\MyLinks.txt"

Sub Sample()
    Dim MyData As String, strData() As String
    Dim i As Long
    Dim ie As Object

    '~~> Open text file in one go
    Open hLinksFile For Binary As #1
    MyData = Space$(LOF(1))
    Get #1, , MyData
    Close #1
    strData() = Split(MyData, vbCrLf)

    Set ie = CreateObject("InternetExplorer.Application")

    ie.Visible = True

    Set XML = CreateObject("msxml2.serverxmlhttp.6.0")

    For i = LBound(strData) To UBound(strData)
        ie.Navigate "about:blank"

        With XML
            .Open "get", strData(i), False
            .send
            ie.Document.body.InnerHTML = .responsetext
        End With

        Do While ie.readystate <> 4: DoEvents: Loop

        ie.Document.body.createtextrange.execCommand "Copy"

        Selection.Paste

        '~~> Move to the end for the next pasting
        Selection.EndKey Unit:=wdStory
        Selection.TypeParagraph: Selection.TypeParagraph

        Doevents
    Next i
End Sub
于 2012-08-13T20:16:34.053 回答