Automatic file name on saving?

T

Troy Bruder

Hello,

I have a Word template that we use to generate new documents... Is there a
way to also give this new document its default "save as" file name??

For example.. When we open the DOT, a new document is created.. Within
that document is an automatically calcuated "ID field" (basically just the
date/time formatted as: MMDDYYHHMMSS)... I want to use that ID field as the
file name when saved so the user doesn't have to type it in and risk a
typo..

Ideas?

Thanks!
Troy
 
D

Doug Robbins

ActiveDocument.SaveAs IdField

Need to know what sort of field you are talking about. If its a formfield,
use

ActiveDocument.SaveAs ActiveDocument.FormFields("IdField").Result

If IdField is the name of a control on a userform, then just the first line
of code should do. In both cases however, you may want to include the path
to the folder where you want the documents saved.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
T

Troy Bruder

Herein lies the problem...

I need to create a unique ID field... So I'm using the Date as: MMDDYY
combined with the Time as HHmmss.... If I use the time from the "date
created" field, I don't get the "seconds" which I need to keep things
unique.. So I'm actually using two ID fields..

Ideas for me?

Troy
 
C

Chad DeMeyer

Troy,

Concatenate the two values. E.g., Date field is 1st in doc and Time field
is 2nd

sPath = "C:\My Path\"
ActiveDocument.SaveAs sPath & ActiveDocument.Fields(1).Result &
ActiveDocument.Fields(2).Result & ".doc"

Of course, IMHO, using date fields for unique IDs is an extremely perilous
course since the values inserted are dependent on local settings for that
computer, which can vary widely from computer to computer. You might want
to check out http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm.

Regards,
Chad
 
Top