Option Explicit
Public sFolder As String
Public EmployeeName, EmployeeId As String
Public fileName As String
Public Sub MergeMail()
'
' MailMerge Macro
'
'
fileName = ActiveDocument.Name
MsgBox fileName
Dim i As Long
UserFormMailMerge.Show
For i = UserFormMailMerge.TextBoxFirstRecord.Value To UserFormMailMerge.TextBoxLastRecord.Value
With Documents(fileName).MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
EmployeeName = .DataFields("Name").Value
EmployeeId = .DataFields("New_Code").Value
End With
.Execute Pause:=False
End With
Public sFolder As String
Public EmployeeName, EmployeeId As String
Public fileName As String
Public Sub MergeMail()
'
' MailMerge Macro
'
'
fileName = ActiveDocument.Name
MsgBox fileName
Dim i As Long
UserFormMailMerge.Show
For i = UserFormMailMerge.TextBoxFirstRecord.Value To UserFormMailMerge.TextBoxLastRecord.Value
With Documents(fileName).MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
EmployeeName = .DataFields("Name").Value
EmployeeId = .DataFields("New_Code").Value
End With
.Execute Pause:=False
End With