Candyman8019
Well-known Member
- Joined
- Dec 2, 2020
- Messages
- 1,089
- Office Version
- 365
- Platform
- Windows
I have a workbook with about 40 sheets. Many of them contain anywhere from 2 to 15 hyperlinks (not hyperlink formulas). We are migrating the files to a new sharepoint site and I need to update all of the hyperlinks. I have a script that will do a REPLACE, so I can specify the starting portion of the URL and change it to the new URL. At one time this script worked for me, but now I'm getting an out of memory error 7 on this line:
hlink.Address = Replace(hlink.Address, oldtxt, newtxt, Compare:=vbTextCompare)
Complete script is as follows:
Any ideas would be appreciated.
hlink.Address = Replace(hlink.Address, oldtxt, newtxt, Compare:=vbTextCompare)
Complete script is as follows:
VBA Code:
Sub UpdateLinks()
Dim hlink As Hyperlink
Dim ws As Worksheet
Dim oldtxt As String
Dim newtxt As String
oldtxt = Sheet253.Range("OLDTXT")
newtxt = Sheet253.Range("NEWTXT")
For Each ws In ThisWorkbook.Worksheets
For Each hlink In ws.Hyperlinks
If InStr(1, hlink.Address, oldtxt) > 0 Then
hlink.Address = Replace(hlink.Address, oldtxt, newtxt, Compare:=vbTextCompare)
End If
Next hlink
Next ws
End Sub
Any ideas would be appreciated.