Reply
 
Thread Tools Display Modes
  #1   Report Post  
RPM7 RPM7 is offline
Junior Member
 
Posts: 1
Default Macro for automatically adding filename without .doc

I have a document that I would like to embed the filename into the header.
The first page of the document has a blank header & the second page has the same header as the remainder of the document.
I initially inserted the field [file name] with Uppercase but it included the ".doc" at the end which I would like to remove. I looked online and most sites say this can't be done. (Plus the field must be updated to take effect)
Instead is it possible to insert a macro that upon saving the file would create a text box in both headers with the filename and the last 4 letters omitted to remove the ".doc".

Does anyone know anything about this?
I'd appreciate any help at all. Thanks.
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Steve Yandl[_3_] Steve Yandl[_3_] is offline
external usenet poster
 
Posts: 11
Default Macro for automatically adding filename without .doc

The subroutine below assumes a document with only one section and will
insert the file name in upper case without the file extension as the left
header on pages 2 and beyond. I didn't take the time to see if this could
be integrated with a sub that intercepts the fileSaveAs normal save and
follows the save with a header update and new save but that might be your
next step.

Steve Yandl

' ----------------------------------------------------------

Sub BaseFileNameHeader()

Dim fso
Dim strFileBaseName As String

Set fso = CreateObject("Scripting.FileSystemObject")
strFileBaseName = fso.GetBaseName(ActiveDocument.Name)
strFileBaseName = UCase(strFileBaseName)

With ActiveDocument.Sections(1)
.PageSetup.DifferentFirstPageHeaderFooter = True
.Headers(1).Range.Text = strFileBaseName
.Headers(wdHeaderFooterFirstPage).Range.Text = ""
End With

Set fso = Nothing

End Sub

' -------------------------------------------------------------

"RPM7" wrote in message
...

I have a document that I would like to embed the filename into the
header.
The first page of the document has a blank header & the second page has
the same header as the remainder of the document.
I initially inserted the field [file name] with Uppercase but it
included the ".doc" at the end which I would like to remove. I looked
online and most sites say this can't be done. (Plus the field must be
updated to take effect)
Instead is it possible to insert a macro that upon saving the file
would create a text box in both headers with the filename and the last
4 letters omitted to remove the ".doc".

Does anyone know anything about this?
I'd appreciate any help at all. Thanks.




--
RPM7


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding filename and path to footer A-non-i-moose New Users 7 February 5th 09 10:09 PM
My file path in my word document is adding Filename on the start? vicki in SantaBarbara Microsoft Word Help 4 December 16th 08 07:06 PM
adding filename & path to footer in office 2007 sb Microsoft Word Help 1 May 20th 08 02:18 AM
Adding field names to filename Peter Microsoft Word Help 2 November 28th 06 11:31 AM
Filename/path-build macro to automatically insert this into a doc blmcity Microsoft Word Help 1 January 28th 05 05:30 PM


All times are GMT +1. The time now is 07:05 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"