0

可能重复:
使用 VBA 从多个单元格中提取超链接

[已修复] 自己排序 :)

对于 i = 3 总计

Cells(i, 11) = Cells(i, 1).Hyperlinks.Item(1).Address
Cells(i, 12) = Cells(i, 2).Hyperlinks.Item(1).Address

 Next i

我从未在 excel 中编写过任何脚本,因此感谢您的帮助。

我想从第 1 列和第 2 列中提取超链接地址 (URL)。然后将它们(不是超链接)粘贴到另一列中(这样我就可以使用链接导出到 CSV)

我想在循环中做这样的事情,但它不起作用!

ActiveSheet.Cells(i, 11).Value = ActiveSheet.Cells(i, 1).Hyperlinks.Item(1).Address


ActiveSheet.Cells(i, 12).Value = ActiveSheet.Cells(i, 2).Hyperlinks.Item(1).Address

谢谢!

4

1 回答 1

0

这是一个关于如何获取工作表前两列中的所有超链接并将它们写入下一个工作表的示例。

Sub getHyperlinks()
'used to keep track of where we are at when writing to the second sheet
Dim iWriteRow As Long
'used to hold how many columns to look through
Dim numberOfCols As Long
numberOfCols = 2
'set initial position
iWriteRow = 1

'variable used in looping through the hyperlinks
Dim h As Hyperlink
'loop through all hyper links on the sheet
For i = 1 To numberOfCols
    For Each h In ActiveWorkbook.Sheets(1).Columns(i).Hyperlinks
        'write them to the next sheet
        ActiveWorkbook.Sheets(2).Cells(iWriteRow, i).Value = h.Address
        'add 1 to our counter
        iWriteRow = iWriteRow + 1
    Next
    iWriteRow = 1
Next i
End Sub
于 2012-11-13T16:18:15.447 回答