用于将网页内容复制到 word/excel 工作表的 Vb 脚本或 VBA 代码 [英] Vb Script or VBA code to copy the contents of a web webpage to a word/excel sheet
问题描述
可能重复:
从 HTML TD 和 Tr 中提取值
我需要使用 VBA 或 VB 脚本将网页的内容复制到 word/excel 工作表(如果使用任何编程语言很忙)..
I need to copy the contents of a web webpage to a word/excel sheet using VBA or VB Script (If it hectic the using any programming language)..
因此,如果我给出网页的路径,那么系统需要复制网页的内容并将其写入 Word 或 excel 文件中.
So if i give the path of a web page then the system needs to copy the contents of a web page and write it in a Word or excel file.
推荐答案
下次请把你已经有的,我有2个解决方案,选择最适合你需要的,这里按要求使用word的一个
Please post what you allready have next time, i have 2 solutions, choose what best suits your needs, here the one that use word as requested
Option Explicit
'Just change these two lines
Const HTMLFileIn="http://stackoverflow.com/questions/10782976/disable-error-in-vbs"
Const DocFileOut="c:
ewfile.doc"
Dim MyWord,oIE
set MyWord=CreateObject("Word.Document")
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Navigate HTMLFileIn
Wscript.Sleep 500
oIE.document.body.createTextRange.execCommand("Copy")
Wscript.Sleep 500
MyWord.Content.Paste
MyWord.SaveAs DocFileOut
MyWord.Close
oIE.Quit
Set oIE = Nothing
set MyWord = Nothing
Wscript.Echo HTMLFileIn & " is now saved as " & DocFileOut
Sub wait
Wscript.Sleep 500
While oIE.busy
Wscript.Sleep 1000
Wend
While oIE.Document.readyState <> "complete"
Wscript.Sleep 1000
Wend
End Sub
如果你只是想查看html,这里是最简单的解决方案
If you just want to view the html, here is the simplest solution
url = "http://stackoverflow.com/questions/10782976/disable-error-in-vbs"
set xml = createobject("msxml2.serverxmlhttp.6.0")
with xml
.open "get", url, false
.send
wscript.echo .responsetext
end with
这篇关于用于将网页内容复制到 word/excel 工作表的 Vb 脚本或 VBA 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!