|
楼主 |
发表于 2023-4-13 15:11
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
看了网址您给的网址。Sub tableTest()
Set winhttp = CreateObject("winhttp.WinHttpRequest.5.1")
Set HTML = CreateObject("htmlfile")
Set oWindow = HTML.ParentWindow
Url = "http://q.10jqka.com.cn/index/"
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
aa = 1
For x = 1 To 256
Url = "http://q.10jqka.com.cn/index/"= * & x
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
Next
Set winhttp = Nothing
Set HTML = Nothing
Set oWindow = Nothing
End Sub
还是加不上循环
|
|