+ Reply to Thread
Results 1 to 3 of 3

Macro to replace part of hyperlink (New Request)

  1. #1
    Registered User
    Join Date
    10-15-2012
    Location
    Fall River MA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Post Macro to replace part of hyperlink (New Request)

    Good Day,

    I have a series of spreadsheets with hyperlinks to PDF files. I am changing the directory of the PDFs and want to update a portion of the hyperlinks from "\\SharedDrive\PublicFolder\AnotherFolderA\AnotherFolderA\2011\CC-11-280.pdf" to "\\SharedDrive\PublicFolder\AnotherFolderB\AnotherFolderB\2011\CC-11-280.pdf"

    There is a thread (called Macro to replace part of hyperlink) which had the following VBA code:

    Sub ReplaceLinks()
    Dim lnk As String, rpl As String
    Dim i As Integer

    rpl = Selection.Value

    For i = 3 To 5
    lnk = Selection.Offset(i, 0).Value
    lnk = Mid(lnk, 1, InStr(1, lnk, "/")) & rpl & Right(lnk, Len(lnk) - InStrRev(lnk, ".html") + 1)
    Selection.Offset(i, 0).FormulaR1C1 = lnk
    Next i
    End Sub

    I modified it and ran it but it also add the updated hyperlink text to the existing displayed text. (CC-11-280 became AnotherFolderB\AnotherFolderBCC-11-280)

    I need to update all of the links in a column where some of the links have been updated and several have not.

    Please help.

  2. #2
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Stellenbosch, South Africa
    MS-Off Ver
    Excel 2003; Excel 2007; Excel 2010; Excel 2013
    Posts
    136

    Re: Macro to replace part of hyperlink (New Request)

    Hi

    Why don't you just use Find & Replace (Control+H). Even if you record it, it should be better than using a loop. I understand using a similar method if you were dealing with hyperlink objects but all you're dealing with is strings.
    • Select the range
    • Invoke Find & Replace (Control+H)
    • Find: \AnotherFolderA\AnotherFolderA\
    • Replace: \AnotherFolderB\AnotherFolderB\
    • Hit OK
    Regards

    Jon (Excel 2003, 2007, 2010, 2013)

  3. #3
    Registered User
    Join Date
    10-15-2012
    Location
    Fall River MA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Macro to replace part of hyperlink (New Request)

    That did not work. It will only allow it in Formulas.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1