Hi Frank,
If you add the following macro to your document, it will update all link paths to point to the parent of the folder where the Word document is located any time it is opened.
Option Explicit Dim TrkStatus As Boolean ' Track Changes flag
Private Sub AutoOpen() ' This routine runs whenever the document is opened. ' It calls on the others to do the real work. ' Prepare the environment. Call MacroEntry ' Most of the work is done by this routine. Call UpdateFields ' Set the saved status of the document to true, so that changes via ' this code are ignored. Since the same changes will be made the ' next time the document is opened, saving them doesn't matter. ActiveDocument.Saved = True ' Go to the start of the document Selection.HomeKey Unit:=wdStory ' Clean up and exit. Call MacroExit End Sub
Private Sub MacroEntry() ' Store current Track Changes status, then switch off temporarily. With ActiveDocument TrkStatus = .TrackRevisions .TrackRevisions = False End With ' Turn Off Screen Updating temporarily. Application.ScreenUpdating = False End Sub
Private Sub MacroExit() ' Restore original Track Changes status ActiveDocument.TrackRevisions = TrkStatus ' Restore Screen Updating Application.ScreenUpdating = True End Sub
Private Sub UpdateFields() ' This routine sets the new path for external links. Dim oRange As Word.Range Dim oField As Word.Field Dim OldPath As String Dim TmpPath 'Array Dim NewPath As String Dim i As Integer NewPath = "" TmpPath = Split(ActiveDocument.Path, "\") For i = LBound(TmpPath) To UBound(TmpPath) - 1 NewPath = NewPath & TmpPath(i) & "\\" Next i ' Go through all story ranges in the document, including shapes, ' headers & footers. For Each oRange In ActiveDocument.StoryRanges ' Go through the fields in the story range. For Each oField In oRange.Fields With oField ' Skip over fields that don't have links to external files If Not .LinkFormat Is Nothing Then ' Get the old path OldPath = Replace(.LinkFormat.SourcePath, "\", "\\") ' Replace the link to the external file .Code.Text = Replace(.Code.Text, OldPath, NewPath) End If End With Next oField Next oRange End Sub
Cheers -- macropod [MVP - Microsoft Word] -------------------------
"Frank" <fkern12[ at ]gmail.com> wrote in message news:1178821117.153774.239080[ at ]e65g2000hsc.googlegroups.com...
[Quoted Text] > Hi, I need to edit the link fields on numerous Word 2003 docs to > change to a relative file path. After unsuccessfully trying and then > reading that it's impossible, I came across the following that > mentions a workaround involving using a custom document property to > store the base filepath: > > http://word.mvps.org/FAQS/TblsFldsFms/includetextfields.htm> > Can someone give me some help on how to accomplish this? Specifically, > I have numerous Word docs sitting in 6 directories. Each word doc > contains a link field to an Excel spreadsheet sitting in the directory > above the word documents. I need to move all of this to another > computer and probably move fairly often, so absolute links are a lot > of work. > > I also read about using find-replace for the link fields, is that a > better solution that using the custom document property workaround? > > Thanks for any help. > > Frank >
|