filename and path field codes in Word 2007

O

ollyaitch

I have a client who wants to use the path to and filename of a word
document as its reference but wants to use part of the file path not
all of it.

so the reference for c:\my documents\folder1\folder2\doc1.doc

should be ..folder1\folder2\doc1.doc

If I use field codes I either get all of the path or none of it. Can
anyone suggest a way to do what my client wants?

Many thanks.
 
G

Graham Mayor

It can't be done with fields. You will need a macro. Something along the
lines of

Sub InsertPartPath()
Dim fPath As String
Dim intPos As Integer
With ActiveDocument
If Len(.Path) = 0 Then
.Save
End If
fPath = .FullName
MsgBox fPath
intPos = InStr(4, fPath, "\")
MsgBox intPos
fPath = ".." & Right(fPath, Len(fPath) - intPos + 1)
MsgBox fPath
End With
End Sub

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
O

OllyAitch

It can't be done with fields. You will need a macro. Something along the
lines of

Sub InsertPartPath()
Dim fPath As String
Dim intPos As Integer
With ActiveDocument
If Len(.Path) = 0 Then
.Save
End If
fPath = .FullName
MsgBox fPath
intPos = InStr(4, fPath, "\")
MsgBox intPos
fPath = ".." & Right(fPath, Len(fPath) - intPos + 1)
MsgBox fPath
End With
End Sub

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









- Show quoted text -

Thanks, I will try and post bak the result.
 

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

Top