VBScript batch html to Word



我正在寻找以下VB的解决方案来批量.html文件/url。我想保存要在 Word 中打开Microsoft.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

试试这个。(久经考验

'~~> Replace this with the text file which has the links
Const hLinksFile As String = "C:TempMyLinks.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

最新更新