我正在尝试将Excel电子表格中的所有超链接拉到新工作表中。我希望列A显示超链接中的文本,列B显示超链接地址。
我已经编写了下面的代码,并且所有B列都可以正常工作,但是A列中的值并不是全部都会过去,而且它们与B列中的超链接地址不匹配。我做错了什么?
提前致谢
Sub extract_links()
Dim hyp As Hyperlink
Dim ReadCols As Long
Dim ReadWriteRow As Long
ReadWriteRow = 1
ReadCols = 6
ActiveWorkbook.Sheets(2).Range("a:b").Clear
For c = 1 To ReadCols
For Each hyp In ActiveWorkbook.Sheets(1).Columns(c).Hyperlinks
ActiveWorkbook.Sheets(2).Range("a" & ReadWriteRow).Value = ActiveWorkbook.Sheets(1).Cells(ReadWriteRow, c).Value
ActiveWorkbook.Sheets(2).Range("b" & ReadWriteRow).Value = hyp.Address
ReadWriteRow = ReadWriteRow + 1
Next
Next c
End Sub
答案 0 :(得分:2)
这次你需要改变这个:
ActiveWorkbook.Sheets(2).Range("a" & ReadWriteRow).Value = ActiveWorkbook.Sheets(1).Cells(ReadWriteRow, c).Value
进入这个:
ActiveWorkbook.Sheets(2).Range("a" & ReadWriteRow).Value = hyp.Range.Value