|
其实我一直是遍历读取Table内容的,今天看到一个帖子求助类似于复制网页表格。我专门搜了一下,还真可以直接复制网页表格,这里我稍微改进了一下,应该有表格的网页都能通用。
参考:https://club.excelhome.net/thread-1192289-1-1.html
参考:https://stackoverflow.com/questi ... oping-through-cells
求助帖:https://club.excelhome.net/thread-1628185-1-2.html
- ''''对应表格复制
- Sub tableTest()
- Set winhttp = CreateObject("winhttp.WinHttpRequest.5.1")
- Set HTML = CreateObject("htmlfile")
- Set oWindow = HTML.ParentWindow
- Url = "https://www.taiwanlottery.com.tw/Lotto/BINGOBINGO/drawing.aspx"
- With winhttp
- .Open "GET", Url, False
- .send
- strText = .responsetext
- '' Debug.Print strText
- End With
- 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 winhttp = Nothing
- Set HTML = Nothing
- Set oWindow = Nothing
- End Sub
- ''''所有表格
- Sub alltableTest()
- Set winhttp = CreateObject("winhttp.WinHttpRequest.5.1")
- Set HTML = CreateObject("htmlfile")
- Set oWindow = HTML.ParentWindow
- Url = "https://www.taiwanlottery.com.tw/Lotto/BINGOBINGO/drawing.aspx"
- With winhttp
- .Open "GET", Url, False
- .send
- strText = .responsetext
- '' Debug.Print strText
- End With
- HTML.body.innerhtml = strText
- Set tables = HTML.getElementsByTagName("table")
- aa = 1
- For i = 0 To tables.Length - 1
- Set Table = tables(i)
-
- '''写入剪切板 第一种
- oWindow.ClipboardData.SetData "text", Table.outerHTML
-
- '''写入剪切板 第二种
- ' Set clipboard = New MSForms.DataObject
- ' clipboard.SetText Table.outerHTML
- ' clipboard.PutInClipboard
-
- ActiveSheet.Cells(1, aa).Select
- ActiveSheet.Paste
- oWindow.ClipboardData.SetData "text", ""
- aa = ActiveSheet.UsedRange.Columns.Count + 2
- Next
- Set winhttp = Nothing
- Set HTML = Nothing
- Set oWindow = Nothing
- End Sub
复制代码
|
评分
-
6
查看全部评分
-
|