I have a Word Merge document that includes a unique id for each section. I want to save each section as a separate file using the unique id as the file name (ex. TL201.doc). I'm merging the data into Word from an Access Database.
Here is my code:
Sub MergeAllRecordsToFolder()
'
' MergeAllRecordsToFolder Macro
Dim x As Long
Dim i As Long
Dim docid2 As String
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
'get the record count of the datasource
With .DataSource
.ActiveRecord = wdLastRecord
x = .ActiveRecord
'set the activerecord back to the first
.ActiveRecord = wdFirstRecord
End With
'loop the datasource count and merge one record at a time
For i = 1 To x
.DataSource.FirstRecord = i
.DataSource.LastRecord = i
.Execute Pause:=True
ActiveDocument.SaveAs FileName:="C:\Documents and Settings\user\My Documents\Projects\TARGETLETTERS\Letters" & i & ".doc"
ActiveDocument.Close wdDoNotSaveChanges
Next i
End With
End Sub
Here is my code:
Sub MergeAllRecordsToFolder()
'
' MergeAllRecordsToFolder Macro
Dim x As Long
Dim i As Long
Dim docid2 As String
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
'get the record count of the datasource
With .DataSource
.ActiveRecord = wdLastRecord
x = .ActiveRecord
'set the activerecord back to the first
.ActiveRecord = wdFirstRecord
End With
'loop the datasource count and merge one record at a time
For i = 1 To x
.DataSource.FirstRecord = i
.DataSource.LastRecord = i
.Execute Pause:=True
ActiveDocument.SaveAs FileName:="C:\Documents and Settings\user\My Documents\Projects\TARGETLETTERS\Letters" & i & ".doc"
ActiveDocument.Close wdDoNotSaveChanges
Next i
End With
End Sub