excel - 从单元格中选择和激活超链接的宏
问题描述
嗨,我无法让我的 VBA 代码激活所选单元格中的超链接。超链接导航到同一工作簿中的另一张工作表,然后代码旨在获取数据并将其粘贴回原始工作表中。
Dim i As Integer
For i = 1 To 6
Cells(i, 3).Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("D7:E7").Select
Selection.Copy
Sheets("Gauge Lab Asset").Select
Cells(i, 22).Select
ActiveSheet.Paste
Next i
我不断收到下标Selection.Hyperlinks(1)
错误
解决方案
避免使用或Select
限定工作表。Range
Cells
Dim i As Long
For i = 1 to 6
With Sheets("Gauge Lab Asset")
.Cells(i, 3).Hyperlinks(1).Follow _
NewWindow:=False, AddHistory:=True
ActiveSheet.Range("D7:E7").Copy _
Destination:=.Cells(i, 22)
End With
Next