Merge data and save the word document every time under new name

R

Roman Timchenko

Hi everyone,

I am AS/400 person, but I need to write a micro where
every time after mail merge I have to save a word
document as a new one. I could do it by hardcoding
like this ActiveApplication.SaveAs "C:\LetterMerge1.doc".
It saves it, but next time the server overrides it with
new document. Can anybody help and show me a code that
will concatenate word document with time
and save it?

Thank, Roman.
 
D

Doug Robbins - Word MVP

Hi Roman

Use:.

' Macro created by Doug Robbins to save each letter created by a mailmerge
as a separate file.
Dim Letters As Integer, Counter As Integer
Letters = ActiveDocument.Sections.Count
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
DocName = "LetterMerge" & LTrim$(Str$(Counter)) & Format(Date,
"yyyyMMdd") & ".doc"
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.Sections(2).PageSetup.SectionStart = wdSectionContinuous
ActiveDocument.SaveAs FileName:=DocName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
Counter = Counter + 1
Wend

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top