Hi,
I am am amatuer trying to write a macro that will change the hyperlink paths in a spreadsheet in a range selected by the user (e.g. just those in L2:L3) ... e.g. here a folder of destinatiion documents have been moved.
I have worked out how to change the hyperlinks in a FIXED range.
I have worked out how to get a user-selected (VARIABLE) range,
but my limited knowledge has prevented me from combining the two.
The code I use for a fixed range L2:L3 is
The code I use to get the user-selected range is
I'd be grateful for help of how to change the hyperlinks (as per first code) just within the user-selected variable range (second code).
Or any alternative
Many thanks
Mark
I am am amatuer trying to write a macro that will change the hyperlink paths in a spreadsheet in a range selected by the user (e.g. just those in L2:L3) ... e.g. here a folder of destinatiion documents have been moved.
I have worked out how to change the hyperlinks in a FIXED range.
I have worked out how to get a user-selected (VARIABLE) range,
but my limited knowledge has prevented me from combining the two.
The code I use for a fixed range L2:L3 is
Code:
Sub ChangeHyperlink()
Dim PathToChangeFrom As Variant
Dim PathToChangeTo As Variant
Dim str As String
PathToChangeFrom = InputBox("Input path to be changed")
PathToChangeTo = InputBox("Input new path")
For Each Cell In Range("L2:L3")
On Error Resume Next
str = Cell.Hyperlinks(1).Address
Cell.Hyperlinks(1).Address = Replace(str, PathToChangeFrom, PathToChangeTo, , , vbTextCompare)
Next
End Sub
The code I use to get the user-selected range is
Code:
Dim rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Select Range" '"KutoolsforExcel9"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
I'd be grateful for help of how to change the hyperlinks (as per first code) just within the user-selected variable range (second code).
Or any alternative
Many thanks
Mark