2015-07-02 50 views
1

您好我想從一個網站粘貼到txt文檔的一些數據,是否有可能粘貼在一個新的行而不覆蓋文件? 這是我的代碼,粘貼到一個txt文件沒有覆蓋

Set app = CreateObject("Shell.Application") 
 
For Each window In app.Windows() 
 
    If InStr(1, window.FullName, "iexplore", vbTextCompare) > 0 Then 
 
    Set ie = window 
 
    Exit For 
 
    End If 
 
Next 
 

 
Set fso = CreateObject("Scripting.FileSystemObject") 
 
Set f = fso.OpenTextFile("output.txt", 2, True,utf-2) 
 
f.Write ie.Document.All.Item("resltext").innerText 
 
f.Close

+0

所以你基本上嘗試打開追加模式的文件嗎? – Marged

+1

@ marged正確 – jacob

+0

然後你的解決方案在下面的答案。嘗試在提問之前閱讀文檔 – Marged

回答

0

得到它

f.WriteLine ie.Document.All.Item("resltext").innerText

1

http://www.w3schools.com/asp/met_opentextfile.asp
看起來,如果你改變
集F = fso.OpenTextFile( 「output.txt的」 之類,2,誠然,UTF -2)

設置f = fso.OpenTextFile(「output.txt」,8,True,utf-2)
它將追加到文件的末尾而不是覆蓋。

+0

是的,它的工作,但它粘貼在同一行上的數據,而不是創建一個新行 – jacob

+1

也許第二次寫後馬上換行? 寫「\ n」 –

+0

要在VBScript中編寫換行符,您需要使用'vbCrLf'。 – Bond