在下面的子代码中,我想将它的作用(替换超链接中的子字符串)限制为特定的列。我在 '* 中写了我的快速修复想法。但我似乎找不到一种将单元格的列值保存为 Range 变量的好方法。
Dim MyDoc As Worksheet
Dim MyCell As Range
...
For Each MyCell In MyDoc.UsedRange
If MyCell.Hyperlinks.Count > 0 Then
'* if mycell's columnnumber = 1 then
LinkURL = MyCell(1).Hyperlinks(1).Address
FindPos = InStr(1, LinkURL, FindString)
If FindPos > 0 Then 'If FindString is found
ReplaceLen = Len(FindString)
URLLen = Len(LinkURL)
PreStr = Mid(LinkURL, 1, FindPos - 1)
PostStr = Mid(LinkURL, FindPos + ReplaceLen, URLLen)
NewURL = PreStr & ReplaceString & PostStr
MyCell(1).Hyperlinks(1).Address = NewURL 'Change the URL
End If
'* End if
End If
Next MyCell