kristabelle
New Member
- Joined
- Apr 14, 2002
- Messages
- 4
I have a mail merge document in Word that is pulling data from an Excel worksheet for about 200 unique items. Thru the merge I am trying to create a new document (in Word), save as a new name and move down the records in Excel to create and save as the next record. I would like to do this for each individual record (create & save).
My trouble is that the mail merge creates one big file and saves it as a single file. I have code that I am trying to make work (somehow) to get it to see the individual id's in the excel range that I am merging but I am stuck.
If anyone is familiar with mail merging to create individually saved documents from the master merge record, preferrably with the individual record number as the saved filename, PLEASE let me know.
The code I'm working with is as follows:
Sub SavePart2()
Dim sName As String
Dim sFirstPart As String
Dim sSecondPart As String
sFirstPart "D:filename"
Dim I As Integer
Documents.Open FileName:="path", 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
For I = 1 To wdDefaultLastRecord
.FirstRecord = I
.LastRecord = I
sSecondPart = .DataFields.Count(0).Value & "03"
sName=sFirstPart & sSecondPart
ActiveDocument.SaveAs FileName:=sName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
.Execute Pause:=True
End With
End With
Next
End Sub
-KB
My trouble is that the mail merge creates one big file and saves it as a single file. I have code that I am trying to make work (somehow) to get it to see the individual id's in the excel range that I am merging but I am stuck.
If anyone is familiar with mail merging to create individually saved documents from the master merge record, preferrably with the individual record number as the saved filename, PLEASE let me know.
The code I'm working with is as follows:
Sub SavePart2()
Dim sName As String
Dim sFirstPart As String
Dim sSecondPart As String
sFirstPart "D:filename"
Dim I As Integer
Documents.Open FileName:="path", 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
For I = 1 To wdDefaultLastRecord
.FirstRecord = I
.LastRecord = I
sSecondPart = .DataFields.Count(0).Value & "03"
sName=sFirstPart & sSecondPart
ActiveDocument.SaveAs FileName:=sName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
.Execute Pause:=True
End With
End With
Next
End Sub
-KB