Hi
I'm currently using an MS Word Mailmerge template that extracts data from MS Excel 2010 and outputs to individual files based upon the MAILMERGE FIELD values. All is well except that it processes all rows, even those that have an empty cell in column A. I only want to mailmerge the rows that have a Y in column A but so far have been unable to accomplish this.
The MS Word Macro that I'm currently using is:
Sub MergeAndSaveAsIndividualFiles()
'
' Merge and save as individual files Macro
'
'
Application.ScreenUpdating = False
Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long
Const StrNoChr As String = """*./\:?|"
Set MainDoc = ActiveDocument
With MainDoc
StrFolder = "H:\My Documents\MailMerge\"
For i = 1 To .MailMerge.DataSource.RecordCount
On Error Resume Next
With .MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
If Trim(.DataFields("Review_Plan_No_Field")) = "" Then Exit For
StrName = .DataFields("Review_Plan_No_Field") & "_" & .DataFields("Plan_Issue")
End With
.Execute Pause:=False
End With
For j = 1 To Len(StrNoChr)
StrName = Replace(StrName, Mid(StrNoChr, j, 1), "_")
Next
StrName = Trim(StrName)
With ActiveDocument
.SaveAs FileName:=StrFolder & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
.Close SaveChanges:=False
End With
Next i
End With
Application.ScreenUpdating = True
End Sub
Column A in the spreadsheet has the Label "ACTIVE".
Any help will be appreciated
John
I'm currently using an MS Word Mailmerge template that extracts data from MS Excel 2010 and outputs to individual files based upon the MAILMERGE FIELD values. All is well except that it processes all rows, even those that have an empty cell in column A. I only want to mailmerge the rows that have a Y in column A but so far have been unable to accomplish this.
The MS Word Macro that I'm currently using is:
Sub MergeAndSaveAsIndividualFiles()
'
' Merge and save as individual files Macro
'
'
Application.ScreenUpdating = False
Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long
Const StrNoChr As String = """*./\:?|"
Set MainDoc = ActiveDocument
With MainDoc
StrFolder = "H:\My Documents\MailMerge\"
For i = 1 To .MailMerge.DataSource.RecordCount
On Error Resume Next
With .MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
If Trim(.DataFields("Review_Plan_No_Field")) = "" Then Exit For
StrName = .DataFields("Review_Plan_No_Field") & "_" & .DataFields("Plan_Issue")
End With
.Execute Pause:=False
End With
For j = 1 To Len(StrNoChr)
StrName = Replace(StrName, Mid(StrNoChr, j, 1), "_")
Next
StrName = Trim(StrName)
With ActiveDocument
.SaveAs FileName:=StrFolder & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
.Close SaveChanges:=False
End With
Next i
End With
Application.ScreenUpdating = True
End Sub
Column A in the spreadsheet has the Label "ACTIVE".
Any help will be appreciated
John