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 に答える