在以下的子代码中,我想限制它所做的事情(替换超链接中的子字符串)只在特定的列中进行。我已经在“*”处写下了我快速解决的想法,但是我似乎找不到一种好的方法来获取保存为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