|
楼主 |
发表于 2022-5-26 11:30
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
当出现自动化这类错误时可以试试 VBS 爬虫
简单版的 VBS+VBA 复制网页表格,不用遍历单元格, 这里工作簿需要开着
VBS 代码
- ' Set winhttp = CreateObject("winhttp.WinHttpRequest.5.1")
- ' Set winhttp = CreateObject("MSXML2.ServerXMLHTTP")
- ' Set winhttp = CreateObject("MSXML2.XMLHTTP")
- Set winhttp = CreateObject("Microsoft.XMLHTTP")
- Url = "https://www.taiwanlottery.com.tw/Lotto/BINGOBINGO/drawing.aspx"
- With winhttp
- .Open "GET", Url, False
- '.setRequestHeader "User-Agent", ""
- .send
- strText = .responsetext
- End With
- Dim xlApp, xlBook
- Set xlApp = GetObject(, "Excel.Application")
- '''对应的excel工作簿,对应的宏名称,工作簿名称有的电脑含中文会报错,可以试试 chcp 方法
- xlApp.Application.Run "Id.xlsm!tableTest",Cstr(strText)
- Set winhttp =Nothing
- Set xlApp = Nothing
- WScript.Quit
复制代码 对应的excel工作簿 里的 VBA 代码
- Sub tableTest(strText)
- Set HTML = CreateObject("htmlfile")
- Set oWindow = HTML.ParentWindow
- HTML.body.innerhtml = strText
- Set tables = HTML.getElementsByClassName("tableFull")
- Set Table = tables(0)
-
- '''写入剪切板 第一种
- oWindow.ClipboardData.SetData "text", Table.outerHTML
-
- '''写入剪切板 第二种
- ' Set clipboard = New MSForms.DataObject
- ' clipboard.SetText Table.outerHTML
- ' clipboard.PutInClipboard
- ActiveSheet.Range("a1").Select
- ActiveSheet.Paste
-
- Set HTML = Nothing
- Set oWindow = Nothing
- End Sub
复制代码
|
|