View Single Post
 
Old 12-02-2020, 06:02 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Firstly, note that ActiveDocument and ThisDocument are NOT necessarily the same thing. ActiveDocument is the document that is open and has the focus. ThisDocument is the file that contains the code.

I'm not going to recreate a bunch of content to try your code and explain where it is failing but I can tell you how to debug it yourself.
Change these lines:
Code:
            With .LinkFormat
              OldPath = Left(.SourceFullName, InStrRev(.SourceFullName, "\"))
              ' Replace the link to the external file if it differs.
              If OldPath <> NewPath Then
                .SourceFullName = Replace(.SourceFullName, OldPath, NewPath)
To:
Code:
            With .LinkFormat
              OldPath = Left(.SourceFullName, InStrRev(.SourceFullName, "\"))
              Debug.Print "NewPath: " & NewPath
              Debug.Print "OldPath: " & OldPath
              Debug.Print "Source Full Name: " & .SourceFullName
              StrTmp = Replace(.SourceFullName, OldPath, NewPath)
              Debug.Print "StrTmp: " & StrTmp
              ' Replace the link to the external file if it differs.
              If OldPath <> NewPath Then
                .SourceFullName = StrTmp
Then step through your code or put a break point on the last line above and examine the immediate window to look at the values and determine what is going wrong.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote