View Full Version : Put File Name Of A Document On Line 1 Of The Document.
mikeburg
12-14-2007, 07:30 AM
I am needing auto open VBA code that will center the name "FAX MESSAGE COVER PAGE", the document's file name (always different) & today's date all on line 1 when it's opened (I already have auto open VBA that save the document, with Save As, the user's name in the file name).
For example, when I open the document MW070.doc, it's auto open VBA has saved as MW070mike.doc. What I need is the following centered on the 1st line:
FAX MESSAGE COVER PAGE MW070mike.doc 12-14-07
Keep in mind, the MW070mike.doc, will be MW070sherry.doc if user sherry opens MW070.doc, etc. So the VBA needs to use the new file name in the Line 1 line.
Thanks so very much for all your help. mikeburg
fumei
12-14-2007, 10:59 AM
If I understand correctly, your AutoOpen (and BTW most coders use the newer Document_Open) immediately (upon opening) does a SaveAs with a new name.
OK. Then that is the name.
The name of the active document is Name, as in:
ActiveDocument.Name
So use the text ("FAX MESSAGE COVER PAGE"), plus .Name plus the formatted date. The text string would be like this:"FAX MESSAGE COVER PAGE " & _
ActiveDocument.Name & " " & _
Format(Now, "mm-dd-yyyy")Note the added spaces to make it like your sample.
As for the format of the paragraph (centered), no one will be surprised if I state that your inserted text should use a Style.
You do not state the content of the document - whether there is existing text, or not - so regarding placing on the "first line", the code used could be various things.
BTW: be careful with the use of the term "line".
And there you go.
mikeburg
12-14-2007, 01:36 PM
Wonderful! I have a stupid question though since this is the 1st time I am using VBA with MS Word. I have been using VBA with Excel quite a while.
How do you put the above line on line 1? In other words, how do I select or specify it to go to line 1? In excel I would use Range("A1:A1") = .
Any tips to jumpstart learning VBA in MS Word is appreciated too.
Thanks a million. mikeburg
fumei
12-14-2007, 01:45 PM
As I stated...it depends. Again, you make no mention of any existing content (or if there is any) in the document.
Again, be careful of the use of "line". Do you mean paragraph?
Is it a blank document? Is it not a blank document?
fumei
12-26-2007, 07:26 AM
Ummmm, did you settle this?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.