LackLuster63
New Member
- Joined
- Mar 14, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hello - I need to move a folder containing test reports to a new server location. There is a spreadsheet with hyperlinks to the test reports that will be broken when the folder is moved. I'd like to swap out the old folder location with a new one for each of the links in the spreadsheet. For example:
Old file path
EVrD23mkqjtNoAgekM2CVJ4BeVZFYbjp0h5TdENOLOY35A?e=vbqYwT
New file path
EVrD23mkqjtNoAgekM2CVJ4BeVZFYbjp0h5TdENOLOY35A?e=vbqYwT
An older post featured a similar question with the following code as a solution, but I wasn't able to make it work for my application:
Sub AlterHyperlinks()
Dim c As Range
Dim pos As Long
Dim tmp As String
Const sNewPath As String = "\\DAVINCI-1\COMMON\MSDS Database"
For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
If c.Hyperlinks.Count > 0 Then
tmp = c.Hyperlinks(1).Address
pos = InStrRev(tmp, "\", InStrRev(tmp, "\") - 1)
If pos > 0 Then c.Hyperlinks(1).Address = sNewPath & Mid(tmp, pos)
End If
Next c
End Sub
Old file path
EVrD23mkqjtNoAgekM2CVJ4BeVZFYbjp0h5TdENOLOY35A?e=vbqYwT
New file path
EVrD23mkqjtNoAgekM2CVJ4BeVZFYbjp0h5TdENOLOY35A?e=vbqYwT
An older post featured a similar question with the following code as a solution, but I wasn't able to make it work for my application:
Find and replace portions of hyperlinks
- Thread starterwillow1985
- Start dateFeb 17, 2021
Sub AlterHyperlinks()
Dim c As Range
Dim pos As Long
Dim tmp As String
Const sNewPath As String = "\\DAVINCI-1\COMMON\MSDS Database"
For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
If c.Hyperlinks.Count > 0 Then
tmp = c.Hyperlinks(1).Address
pos = InStrRev(tmp, "\", InStrRev(tmp, "\") - 1)
If pos > 0 Then c.Hyperlinks(1).Address = sNewPath & Mid(tmp, pos)
End If
Next c
End Sub