Hi Steve,
If you can keep the Word document and the included ones in the same folder
for distribution (whether by email or on a CD, for exmple), you could use
the following vba code to automatically update the INCLUDETEXT filed paths
whenever the document is opened.
Cheers
PS: e-mailing might break the longer lines. If this causes problems for you
in restoring them correctly, post back and I'll let you know which ones need
fixing.
Option Explicit
Public TFilePath As String, SFileName As String
Private Sub UpdatePath()
' This code defaults to the same path as the target document,
' using the simple expedient of creating,
' copying, then destroying a FILENAME/p field.
Dim CharPos As Integer, TFilePathLength As Integer
With Selection
.Collapse Direction:=wdCollapseStart
.Fields.Add Range:=Selection.Range, Type:=wdFieldFileName, _
Text:="\p"
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
TFilePath = Selection
TFilePathLength = Len(TFilePath)
For CharPos = TFilePathLength To 0 Step -1
If Mid(TFilePath, CharPos, 1) = "\" Then
TFilePath = Mid(TFilePath, 1, CharPos)
Exit For
End If
Next CharPos
Selection.Delete
' Insert the required \\s and 'INCLUDETEXT "' prefix for the string
TFilePath = Replace$(TFilePath, "\", "\\")
TFilePath = "INCLUDETEXT " & """" & TFilePath
End Sub
Private Sub GetSourceFileName()
' This routine gets the source filename, plus any bookmarks
' and switches from the original field.
Dim CharPos As Integer, SFilePathLength As Integer
SFileName = Selection
SFilePathLength = Len(SFileName)
For CharPos = SFilePathLength To 0 Step -1
On Error Resume Next 'In case there's no path
If Mid(SFileName, CharPos, 2) = "\\" Then
SFileName = Mid(SFileName, CharPos + 2)
Exit For
End If
Next CharPos
' The next two lines stop the new field from gaining extra spaces.
SFileName = Replace$(SFileName, " " & Chr(21), Chr(21))
SFileName = Replace$(SFileName, Chr(21), "")
End Sub
Sub AutoOpen()
Dim FieldCount As Integer, Found As Boolean, NewField As String
Selection.HomeKey Unit:=wdStory
ActiveWindow.View.ShowFieldCodes = False
Call UpdatePath
ActiveWindow.View.ShowFieldCodes = True
' Go through the document, updating all INCLUDETEXT fields
' with the new path.
If ActiveDocument.Fields.Count > 0 Then
For FieldCount = ActiveDocument.Fields.Count To 1 Step -1
ActiveDocument.Fields(FieldCount).Select
If InStr(1, Selection.Fields(1).Code, "INCLUDETEXT", 1) Then
Selection.Copy
Call GetSourceFileName
NewField = TFilePath & SFileName
With Selection
.Delete
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
Text:=NewField, PreserveFormatting:=False
End With
End If
Next
End If
ActiveWindow.View.ShowFieldCodes = False
ActiveDocument.Saved = True
End Sub