如何使用VBA从多个超链接中删除文本

第一次发帖,我很抱歉,如果答案是明显的。

我做了一些search,并通过这个post和一些谷歌search,设法组装这个Excel的VBAmacros:

Sub GetFeats() Dim SourceCell As Range Dim FeatText As String Dim TargetCell As Range Dim appIE As Object Set appIE = CreateObject("internetexplorer.application") Visible = True For Each SourceCell In Sheets("Sheet2").Range("A2:A3200") With appIE .Navigate SourceCell .Visible = True End With Do While appIE.Busy DoEvents Loop FeatText = appIE.document.getElementById("content") For Each TargetCell In Sheets("Sheet2").Range("B2:B3200") b2 = TargetCell Next TargetCell Next SourceCell End Sub 

现在看起来好像差不多了。 我可以看到Internet Explorer在A2:A3200范围内运行,相继打开每个链接。 它到达一个空单元格时会失败,因此,如果单元格是空的,我将需要search一个方法来告诉它跳过一个单元格,但是我想我可以自己pipe理它。

问题在于它没有find网页的“内容”。 我想知道是否也许div id是不一样的,在function上,因为tr id (用于原来的post我采购)。 我认为 ,如果我能得到VBAfind正确的内容,它将正确粘贴,范围B2:B3200,但现在它只是粘贴“[object HTMLDivElement]”

对于上下文,下面是从A2:A3200中拉出的一个链接的示例。

谢谢大家。

哼,你有点迷失了我。 你是说你在列中有链接,就像列A一样,而且你想把一个站点的全部内容导入到一个相邻的单元格中,就像列B中的下一个单元格一样? 这是问吗? 如果是的话,试试这个。

 Sub Sample() Dim ie As Object Dim retStr As String Dim sht As Worksheet Dim LastRow As Long Dim rCell As Range Dim rRng As Range Set sht = ThisWorkbook.Worksheets("Sheet1") 'Ctrl + Shift + End LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row Set ie = CreateObject("internetexplorer.application") Set rRng = Sheet1.Range("A1:A" & LastRow) For Each rCell In rRng.Cells With ie .Navigate rCell.Value .Visible = True End With Do While ie.readystate <> 4: Wait 5: Loop DoEvents rCell.Offset(0, 1).Value = ie.document.body.innerText Next rCell End Sub Private Sub Wait(ByVal nSec As Long) nSec = nSec + Timer While nSec > Timer DoEvents Wend End Sub