刚刚在这里注册了一个帐户,是的,我是一个真正的菜鸟 - 请对我好一点。现在我面临的挑战是:我正在用 VBA 构建一个网络抓取工具,并找到了一个代码,我根据自己的需要做了一些修改。一切都很完美,而且实际上非常顺利。现在我希望加载到我的 exel 文档中的文本不要太长,而是很宽。我怀疑它与“.Offset(I,j)”有关。我玩过一点,但我只是设法毁了一切。这是我使用的代码:
Dim IE As InternetExplorer
Dim htmldoc As MSHTML.IHTMLDocument 'Document object
Dim eleColtr As MSHTML.IHTMLElementCollection 'Element collection for tr tags
Dim eleColtd As MSHTML.IHTMLElementCollection 'Element collection for td tags
Dim eleRow As MSHTML.IHTMLElement 'Row elements
Dim eleCol As MSHTML.IHTMLElement 'Column elements
Dim ieURL As String 'URL
'Open InternetExplorer
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
'Navigate to webpage
ieURL = "#"
IE.Navigate ieURL
'Wait
Do While IE.Busy Or IE.ReadyState <> 4
DoEvents
Loop
Set htmldoc = IE.Document 'Document webpage
Set eleColtr = htmldoc.getElementsByTagName("tr") 'Find all tr tags
'This section populates Excel
I = 0 'start with first value in tr collection
For Each eleRow In eleColtr 'for each element in the tr collection
Set eleColtd = htmldoc.getElementsByTagName("tr")(I).getElementsByTagName("td") 'get all the td elements in that specific tr
j = 0 'start with the first value in the td collection
For Each eleCol In eleColtd 'for each element in the td collection
Sheets("Sheet1").Range("A1").Offset(I, j).Value = eleCol.innerText 'paste the inner text of the td element, and offset at the same time
j = j + 1 'move to next element in td collection
Next eleCol 'rinse and repeat
I = I + 1 'move to next element in td collection
Next eleRow 'rinse and repeat
End Sub ```
慕村225694
相关分类