How do I change footer to only show 1 level of path and file name

G

Guest

I want to put footer on a document (word and excel) but I only want to show
one level of the path and file name. ex: C:\...\folder\file name. The
choices in the list only give path and file or file name. Path and file name
is too long. Ex: C:\Documents and Settings\Owner\My Documents\folder
name\file name. C:\folder name\file name is sufficient.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?Um9zZSBN?=,
I want to put footer on a document (word and excel) but I only want to show
one level of the path and file name. ex: C:\...\folder\file name. The
choices in the list only give path and file or file name. Path and file name
is too long. Ex: C:\Documents and Settings\Owner\My Documents\folder
name\file name. C:\folder name\file name is sufficient.
there is no built-in option for what you want. You'd need to use a macro
solution, which could get a bit complicated if the path needs to update whenever
the document is opened and/or saved.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Stefan Blom

If the problem is that the full path takes up too much space in your
footer, you could simply decrease the font size of the Footer
paragraph style.

Alternatively, you can use the macro below which provides a
semi-automatic way to create paths of the type
"C:\..\folder\filename". The macro creates a document variable named
CustomPath (if necessary). If a file has been moved to a different
location, just run the macro again to update the value of CustomPath.

To display the value of CustomPath in your document you would use the
field { DOCVARIABLE "CustomPath" }. To insert this field, press
CTRL+F9, type DOCVARIABLE "CustomPath" between the field delimiters,
and press F9.

After you've updated the value of the doc variable (by using the
macro), you can switch to Print Preview which will force an update of
the field.

Sub DetermineCustomPath

Dim FullPath As String, Temp As String
Dim Pos1 As Long, Pos2 As Long
Dim RootFolder As String
Dim TheResult As String
Dim v As Variable

FullPath = ActiveDocument.Path

Pos1 = InStr(FullPath, "\")
RootFolder = Left(FullPath, Pos1)

Temp = StrReverse(FullPath)
Pos2 = InStr(Temp, "\")
TheResult = Right(FullPath, Pos2)

For Each v In ActiveDocument.Variables
If v.Name = "CustomPath" Then
v.Value = RootFolder & ".." & TheResult & "\" & _
ActiveDocument.Name
Exit Sub
End If
Next v
ActiveDocument.Variables.Add "CustomPath", RootFolder & ".." & _
TheResult & "\" & ActiveDocument.Name

End Sub

--
Stefan Blom
Microsoft Word MVP


in messsage
news:[email protected]...
 
S

Stefan Blom

Hmm, I just realized that the code in my previous reply doesn't
consider the case when a file is located in a root folder, such as
C:\. The code below does, which improves things a bit (but there are
other special situations that should be taken care of).

Note: If you need help with installing the macro, see:
http://gmayor.com/installing_macro.htm.

'Modified code example:
Sub DetermineCustomPath2
Dim FullPath As String, Temp As String
Dim Pos1 As Long, Pos2 As Long
Dim RootFolder As String
Dim TheResult As String
Dim v As Variable

FullPath = ActiveDocument.Path

Pos1 = InStr(FullPath, "\")
If Pos1 = 0 Then
TheResult = ActiveDocument.FullName
Else
RootFolder = Left(FullPath, Pos1)

Temp = StrReverse(FullPath)
Pos2 = InStr(Temp, "\")
TheResult = Right(FullPath, Pos2)
TheResult = RootFolder & ".." & TheResult & "\" & _
ActiveDocument.Name
End If
For Each v In ActiveDocument.Variables
If v.Name = "CustomPath" Then
v.Value = TheResult
Exit Sub
End If
Next v
ActiveDocument.Variables.Add "CustomPath", TheResult

End Sub
 
G

Graham Mayor

My fellow MVPs have offered solutions based on what you have, but don't
overlook the obvious. Move your Word documents folder to a folder directly
off the root eg C:\Foldername (Tools > options > file locations > Documents)
and you won't have a long path to deal with ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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