link paths don't all change with folder name change

I have a project where Excel files and Word files (all 2007) link back and forth.

All are Excel->Word or Word->Excel. I changed the name of the folder that contains

all of this to include a date so we keep track of which backup version is which.

I migrated the folder to my wife's computer & found out a lot of the hyperlinks failed

to work, 8 altogether out of dozens, and ALL of them Word->Excel. I discovered the

hyperlink paths had the paths from my computer which didn't make me feel good.

When I checked them on my computer the problem was these hyperlinks had the old

folder name while the rest of them reflected the new folder name. So the same errors

happened on my computer. I just didn't notice the old folder name in the paths on my wife's machine.

I did a little test using a folder with just one Excel file and 2 Word files. When I changed the

small test folder name one of the return Word hyperlinks failed to change its path & had the

old folder name.  But I could not get this action to repeat so I can't isolate something I may

or may not have done.

Any clues? Is something wrong with my brain?  Yeah, I know, I know.

Answer
Answer

I gather that some links are automatically changing and others not.  I am surprised that any of them would change.

Here however is macro that can be used to update the links in a document to reflect a change in the source file location.

' Macro created 26/10/01 by Doug Robbins to update links in a document
'
Dim alink As Field, linktype As Range, linkfile As Range
Dim linklocation As Range, i As Integer, j As Integer, linkcode As Range
Dim Message, Title, Default, Newfile
Dim counter As Integer

 

counter = 0
For Each alink In ActiveDocument.Fields
    If alink.Type = wdFieldLink Then 

        Set linkcode = alink.Code
        i = InStr(linkcode, Chr(34))
        Set linktype = alink.Code
        linktype.End = linktype.Start + i
        j = InStr(Mid(linkcode, i + 1), Chr(34))
        Set linklocation = alink.Code
        linklocation.Start = linklocation.Start + i + j - 1
        If counter = 0 Then
            Set linkfile = alink.Code
            linkfile.End = linkfile.Start + i + j - 1
            linkfile.Start = linkfile.Start + i
            Message = "Enter the modified path and filename following this Format " & linkfile
            Title = "Update Link"
            Default = linkfile
            Newfile = InputBox(Message, Title, Default)
        End If
        linkcode.Text = linktype & Newfile & linklocation
        counter = counter + 1
    End If
Next alink

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 1,453 Applies to: