![]() |
|
|
|
#1
|
||||
|
||||
|
The following will work, however may I suggest you look at the merge to documents mode of E-Mail Merge Add-in
Code:
Option Explicit
Sub SaveIndividualWordFiles()
Dim i As Long
Dim docMail As Document
Dim docLetters As Document
Dim savePath As String, sFName As String
Set docMail = ActiveDocument
savePath = docMail.path & "\"
With docMail.MailMerge
For i = 1 To .DataSource.RecordCount
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
'' This will be the file name
'' the test data source had unique surnames
'' in a field (column) called FileName
sFName = .DataFields("Title").value
End With
.Execute Pause:=False
Set docLetters = ActiveDocument
' Save generated document and close it after saving
docLetters.SaveAs FileName:=savePath & sFName & ".docx"
docLetters.Close False
DoEvents
Next
End With
Set docMail = Nothing
Set docLetters = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
|||
|
|||
|
@gmayor
I have tried the code you posted with no success. Using step into, it gets to "For i = 1 To .DataSource.RecordCount" and moved straight to "End With" Any thoughts or advice? Unfortunately I don't have to option to install an Add-in for this. |
|
| Tags |
| mail merge, mail merge code, mail merge saving |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to mail merge next record on same page to save paper
|
klc9761 | Mail Merge | 1 | 04-22-2017 02:29 PM |
Showing record number during mail merge
|
catflap | Mail Merge | 1 | 04-13-2017 07:32 AM |
Mail Merge Next Record If rule
|
RHensley | Mail Merge | 10 | 03-07-2017 08:05 AM |
Automate daily mail merge
|
JCInfo | Mail Merge | 4 | 12-02-2013 05:12 PM |
| avoid duplicete record and merge the record with the existed record | hemant.behere | Excel | 0 | 01-10-2012 02:53 AM |