sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
The following post is cross-posted at Need help with changing hyperlink addresses
I've used similar code like what I have below with much success. However, this time the hyperlinks changed such that they have the "%20" in the address for spaces. I need to get the "%20" replaced with spaces and get the first part of that file path changed to the new string I have specified. When I run the code I get the error "Run-time error '7': Out of Memory at the line that after "Else". I have no clue what I have wrong here. Any help would be much appreciated. Thanks, SS
I've used similar code like what I have below with much success. However, this time the hyperlinks changed such that they have the "%20" in the address for spaces. I need to get the "%20" replaced with spaces and get the first part of that file path changed to the new string I have specified. When I run the code I get the error "Run-time error '7': Out of Memory at the line that after "Else". I have no clue what I have wrong here. Any help would be much appreciated. Thanks, SS
VBA Code:
Sub FixPOHyperlinks()
Dim wBook As Workbook
Dim wSheet As Worksheet
Dim tb As ListObject
Dim OldStr As String, NewStr As String
Dim hyp As Hyperlink
Dim sOldAddress As String, sNewAddress As String
Set wBook = ThisWorkbook
Set wSheet = wBook.Sheets("Sheet1")
Set tb = wSheet.ListObjects("Table1")
Worksheets("Sheet1").Activate
OldStr = "https://companyname-my.sharepoint.com/personal/mescobal_companyname_com/Documents/H%20drive"
NewStr = "\\abc.local\DEM"
For Each wSheet In Worksheets
For Each hyp In tb.ListColumns("Machine PO").DataBodyRange.Hyperlinks
If InStr(1, hyp.Address, "\") > 0 Then
hyp.Address = Replace(hyp.Address, OldStr, NewStr)
hyp.Address = Replace(hyp.Address, "%20", Chr(32))
Else
hyp.Address = NewStr & "\" & hyp.Address
End If
'hyp.TextToDisplay = Replace(hyp.Address, OldStr, NewStr)
Next hyp
Next
End Sub