Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save MS Word merged file with date for name

Status
Not open for further replies.

kirnavi

Technical User
Feb 4, 2002
29
0
0
US
Hi -

I have a form letter that uses an Access query for its data source. This letter will be produced several times a week. Once the letter has merged to a new document, I want the end document to save and name itself automatically. For instance, I would want a letter produced today to be named "20020618.doc". I don't want to go the InputBox route due to user errors.

I know this is wrong, but here's what I have so far:

Sub welcomeletter()
Dim name
ChangeFileOpenDirectory _
"\\Case Data\\WelcomeLetters\"
Documents.Open filename:="""welcomeletter.DOC""", ConfirmConversions _
:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
filedate = Date
filename = filedate + ".doc"
ChangeFileOpenDirectory _
"\\Case Data\WelcomeLetters\Complete\"
ActiveDocument.saveas filename:=filename, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveDocument.Close
ActiveDocument.Close
End Sub



Can anyone help?

Thanks,
Susan
 
do not have time to test the rest of your code but you could try changing

Code:
filedate = Date
filename = filedate + ".doc"

to

Code:
filename = format$(date,"YYYYMMDD") + ".doc"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top