SharePoint Diva

November 5, 2008

Replacing Multiple Hyperlink Values in a List

Filed under: Uncategorized — sharepointdiva @ 8:13 pm

I rather embarrassed of this solution, but I’m hoping that if I post what I’m doing some else out there will know of a better way.

 
 

I have a long list with hyperlinks. I reuse this list in multiple locations and need to change the location name in the URL. I export the list to a spreadsheet and launch the Visual Basic editor. I then run the following code:

 
 

Sub ReplaceHyperlinkAdresses()

Dim hypLink As Hyperlink

Dim ws As Worksheet

 

For Each ws In Worksheets

For Each hypLink In ws.Hyperlinks

If hypLink.Address Like “http://server/sites/department/Documents/Forms/OLDLOCATION.aspx*” Then

hypLink.Address = _

Replace(hypLink.Address, “http://server/sites/department/Documents/Forms/OLDLOCATION.aspx“, “http://server/sites/department/Documents/Forms/NEWLOCATION.aspx“)

End If

Next hypLink

Next ws

End Sub

 
 

Afterwards, I copy and paste the column with the hyperlinks back into my list using the datasheet view. It works, but I feel like there should be a better way to update a list of hyperlinks in a SharePoint list.

 
 

Blog at WordPress.com.