+ Reply to Thread
Results 1 to 6 of 6

Replacing Hyperlinks in an Entire Workbook

  1. #1
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    133

    Replacing Hyperlinks in an Entire Workbook

    For some reason my workbook that contains links hyperlinks to a networked drive at times reverts those inks to my own appdata location. I can't figure out how that happens, but I'd like to mass change them back to the correct network location. I found the following VBA code but it's not working. When testing the variable hlink.address always looks to be blank. Can someone tell me what's wrong with this code?
    Please Login or Register  to view this content.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Replacing Hyperlinks in an Entire Workbook

    Is your Excel version still 2003? Or has it changed?

    If newer, likely culprit is Hyperlink base setting in the file.
    0.JPG

    If it is blank like above, set it to some non-existent location Ex: "\\ServerX\X\X\"

    This will force the file to use absolute link for all hyperlinks and will not change based on workbook location.

    Alternately, instead of using regular hyperlinks. You could use HYPERLINK formula to construct link.

    Looking at code, maybe issue is with "/" mixed with "\". It's usually one or the other.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Forum Contributor
    Join Date
    12-02-2010
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2013, 2016
    Posts
    100

    Re: Replacing Hyperlinks in an Entire Workbook

    js0873,

    I constructed a little test and was able to get the address to change on my hyperlink using your code. I did obviously have to mess with the paths to make them specific to me but that shouldn't be a huge deal for you to fix. I would suggest finding where it's pointing now and pasting that string of text into windows explorer to make sure the link is properly formatted. When I stepped through the code (F8) the hLink.Address populated properly, double check the actual address that the hyperlink is pointing to (not just what is displayed) and verify it is entered correctly in the code. Secondarily I agree that the HYPERLINK function in Excel may be an easier way to construct your spreadsheet.

    Hope this is helpful, if not please post again and we'll try to help.

    DarkF1ame
    Mark as "Solved" and add Reputation if applicable.

  4. #4
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    133

    Re: Replacing Hyperlinks in an Entire Workbook

    Quote Originally Posted by CK76 View Post
    Is your Excel version still 2003? Or has it changed?

    If newer, likely culprit is Hyperlink base setting in the file.
    Attachment 549552

    If it is blank like above, set it to some non-existent location Ex: "\\ServerX\X\X\"

    This will force the file to use absolute link for all hyperlinks and will not change based on workbook location.

    Alternately, instead of using regular hyperlinks. You could use HYPERLINK formula to construct link.

    Looking at code, maybe issue is with "/" mixed with "\". It's usually one or the other.
    My Excel version is 2013, and the Hyperlink Base is set to blank. If I set it to something none existent, what'll that do? Also, the same question applies to using a Hyperlink formula vs. just adding and editing a hyperlink. Is the purpose of doing that either of these so that it won't ever change again back to my own appdata location and maintain whatever I've entered?

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Replacing Hyperlinks in an Entire Workbook

    By setting it to something non-existent, it will force hyperlink to be absolute link at all times.
    I.E. will always have full file path.
    Ex: \\Servername\folder\file.xlsx instead of somthing like .\folder\file.xlsx. Which is relative link. Based on workbook location.

    Correct, by using absolute link either by above method or using Hyperlink function, Excel will always use network drive location and will not adjust link path to your local folder.

  6. #6
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    133

    Re: Replacing Hyperlinks in an Entire Workbook

    Quote Originally Posted by DarkF1ame View Post
    js0873,

    I constructed a little test and was able to get the address to change on my hyperlink using your code. I did obviously have to mess with the paths to make them specific to me but that shouldn't be a huge deal for you to fix. I would suggest finding where it's pointing now and pasting that string of text into windows explorer to make sure the link is properly formatted. When I stepped through the code (F8) the hLink.Address populated properly, double check the actual address that the hyperlink is pointing to (not just what is displayed) and verify it is entered correctly in the code. Secondarily I agree that the HYPERLINK function in Excel may be an easier way to construct your spreadsheet.

    Hope this is helpful, if not please post again and we'll try to help.

    DarkF1ame
    I found my problem. The replace function had a typo, but the main thing with testing and seeing nothing was that I thought that this was only processing cells that had a hyperlink assigned ...

    For Each hLink In wSheet.Hyperlinks

    Instead it's processing all cells. I didn't realize that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro for Mass Replacing Hyperlinks - Error 7 Out Of Memory
    By PanicAcid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-17-2017, 12:25 PM
  2. replace doesn't search for the entire word before replacing
    By william1404 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2014, 03:28 AM
  3. Replacing Old Hyperlinks with Hyperlink Functions on Shared Spreadsheet
    By mjliver in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-18-2013, 08:46 AM
  4. Replies: 0
    Last Post: 02-14-2012, 12:34 PM
  5. adding data to another workbook (replacing entire record if value in cell A matches)
    By ecc34_11 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2011, 08:47 AM
  6. Removing and replacing hyperlinks
    By wtcamb in forum Excel General
    Replies: 0
    Last Post: 04-17-2011, 06:47 PM
  7. Replacing Hyperlinks
    By maxwku in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-06-2010, 05:37 PM

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