Includetext Source Path Office 2003

S

Steve

I am trying "NOT" to include a path name in my fields. I want to keep
all my documents in one folder without typing in the path for the
document. I read on previous postings that it is possible in Office
2000 do do this. I am having problems with this.

I keep getting: {INCLUDETEXT "Lease.doc" \!} --- my code
Error! Not a valid filename. --- result
When I include the path "c:\\template\\Lease.doc" there is no problem.
I have office 2003 and I am having problems getting it to work without
a path. The reason I need this done is I have a document I am sending
to someone and I don't want the path from my computer appearing in the
field.

Is there something I am typing wrong?

Thanks

Steve
 
M

macropod

Hi Steve,

In Word 2000, at least, the full path isn't necessary. However, the full
path is still stored in the document's meta data, and the INCLUDETEXT field
will still use that path, even in Word 2003.

One implication for this in what you're trying to do is that, if you send
only the 'target' document, the recipient won't be able to see the 'source'
document's included text - they'll simply get the same 'Error! Not a valid
filename' you're getting now. To overcome this, you might like to convert
the included text to standard text (via Ctrl-Shift-F9) and save that version
of the document under a new filename for sending. Doing this removes all
links to the 'source' document.

Cheers
 
S

Steve

macropod said:
Hi Steve,

In Word 2000, at least, the full path isn't necessary. However, the full
path is still stored in the document's meta data, and the INCLUDETEXT field
will still use that path, even in Word 2003.

One implication for this in what you're trying to do is that, if you send
only the 'target' document, the recipient won't be able to see the 'source'
document's included text - they'll simply get the same 'Error! Not a valid
filename' you're getting now. To overcome this, you might like to convert
the included text to standard text (via Ctrl-Shift-F9) and save that version
of the document under a new filename for sending. Doing this removes all
links to the 'source' document.

Cheers

Thank you for the info on this I will need this tip as well. What I
have is a template with linked documents. I am creating this template
and linked documents on my computer. I will then send this template
and the linked documents all in one folder to another user. When the
user opens the template that has the linked documents it returns the
Error! Not a valid filename.

Is this possible in 2003 to have the source and linked docs contained
in one folder and exclude the path name in the includetext field?

Steve
 
M

macropod

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
 
S

Steve

Macropod:

This macro works great. I don't see any problems at all with it. Is
there a way I can ask the user when the document opens if they want to
run the macro? Right now it runs everytime you open the document.

Thanks again.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top