Display "folder name" in text

  • Thread starter Shim E via OfficeKB.com
  • Start date
S

Shim E via OfficeKB.com

I am running Word 2000 and I am trying to figure out how to display just the
folder name into a word text, header, and footer. I have come to the
conclusion this will require a macro. But i am not smart enough to know the
code. Basically, I want to be able to hit a hotkey or button on my toolbar
and display the "folder name" without any address attached to it. I want it
to print in the current font and size. Much like the "file name" autotext
feature. I will also need instructions on how to add this to normal.dot.
Thank-you for your help, and I apologize if this has been already covered. I
might have been searching with the wrong keywords or something.
 
H

Helmut Weber

Hi Shim,

you may

put an inklusive bookmark in the header,
preferebly in the header of a template,
which looks like [Foldername], and call it "Folderheader".

And

put an inklusive bookmark in the footer,
preferebly in the footer of a template,
which looks like [Foldername], and call it "FolderFooter".

And

put several REF-Fields in the doc's mainstory,
which look like { REF FolderHeader }.

And try:

Sub InsertFolderName()
Dim strF As String ' the folder name
Dim rngT As Range ' a temporary range
' get name of folder
' hard for a beginner, though
strF = ActiveDocument.FullName
strF = StrReverse(strF)
strF = Right(strF, Len(strF) - InStr(strF, "\"))
strF = Left(strF, InStr(strF, "\") - 1)
strF = StrReverse(strF)

With ActiveDocument.Bookmarks
.Item ("FolderHeader")
Set rngT = .Item("FolderHeader").Range
rngT.Text = strF
.Add Name:="FolderHeader", Range:=rngT
.Item ("FolderFooter")
Set rngT = .Item("FolderFooter").Range
rngT.Text = strF
.Add Name:="FolderFooter", Range:=rngT
End With
ActiveDocument.Fields.Update
End Sub

Put sub InsertFolderName in Normal.dot.

Try to work your way through "Tools, Customize".

From then on it's not a matter of programming anymore.

Lots of other solutions possible.

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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