Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Insert the filename field in the footer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hb - 22 Nov 2006 23:50 GMT
I'd like to insert the filename field in the footer after a string ("File
Name:-").

thanks in advance.
Jezebel - 23 Nov 2006 00:01 GMT
Assuming you've already read the Help page on Filename fields, what problem
have you run into?

> I'd like to insert the filename field in the footer after a string ("File
> Name:-").
>
> thanks in advance.
hb - 23 Nov 2006 00:30 GMT
I do a mailmerge in Word 2003 which removes all the really useful stuff like
bookmarks and fields by default.  So, I need a way of inserting the filename
field in the footer in a specific place so that when the user does a 'save
as'  they get the file name.  I thought I'd use the 'File Name:-' string as a
pseudo-bookmark and place the filename field  after it.

> Assuming you've already read the Help page on Filename fields, what problem
> have you run into?
[quoted text clipped - 3 lines]
> >
> > thanks in advance.
Jezebel - 23 Nov 2006 00:49 GMT
Seems a reasonable approach. What's the question?

>I do a mailmerge in Word 2003 which removes all the really useful stuff
>like
[quoted text clipped - 14 lines]
>> >
>> > thanks in advance.
hb - 23 Nov 2006 11:01 GMT
Ultimately, I want {FileName \p} to appear after the 'File Name:-' string
like so

File Name:-c:\test.doc

So, I want to modify this code, which just inserts the file name field in
the start of the footer,  to find the 'File Name:-' string and insert the
field after it.

Sub PutFileNameOnLastPage()
  ' Are any documents open?
  If Documents.Count = 0 Then Exit Sub
  ' Go to footer of document in the last section
  ' of the document.
  Selection.EndKey Unit:=wdStory
  If ActiveWindow.ActivePane.View.Type = wdNormalView Or _
     ActiveWindow.ActivePane.View.Type = wdOutlineView Or _
       ActiveWindow.ActivePane.View.Type = wdMasterView Then
     ActiveWindow.ActivePane.View.Type = wdPageView
  End If
  ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
  ' If the document already contains a filename, exit this routine.
  For Each ao In Selection.HeaderFooter.Range.Fields
     If ao.Type = wdFieldFileName Then
        ' Just exit
        Exit Sub
     End If
  Next
  ' Add the Filename field.
  ActiveWindow.View.ShowFieldCodes = True
  With Selection
     .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "FILENAME \p "
     Selection.HeaderFooter.Range.Fields.Update
  End With

Regards

HB

> Seems a reasonable approach. What's the question?
>
[quoted text clipped - 16 lines]
> >> >
> >> > thanks in advance.
Jezebel - 23 Nov 2006 11:29 GMT
Dim pRange As Word.Range

Set pRange = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
pRange = "Filename: "
pRange.Collapse Direction:=wdCollapseEnd
pRange.Fields.Add Range:=pRange, Type:=wdFieldFileName, Text:="\p"

> Ultimately, I want {FileName \p} to appear after the 'File Name:-' string
> like so
[quoted text clipped - 58 lines]
>> >> >
>> >> > thanks in advance.
hb - 23 Nov 2006 12:33 GMT
Thanks for that but there is one slight problem.  There is a table with
various information (ie. VAT no. etc) in the footer of the document and this
appears to remove it.

> Dim pRange As Word.Range
>
[quoted text clipped - 65 lines]
> >> >> >
> >> >> > thanks in advance.
Jezebel - 23 Nov 2006 20:04 GMT
Sheesh, you really need spoon-feeding, don't you? Try the InsertAfter
method.

> Thanks for that but there is one slight problem.  There is a table with
> various information (ie. VAT no. etc) in the footer of the document and
[quoted text clipped - 76 lines]
>> >> >> >
>> >> >> > thanks in advance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.