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.