"Compile Error : variable not defined" -while running below code, kindly suggest.

pratzz00

New Member
Joined
Jul 18, 2023
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Please post code within code tags (vba button on posting toolbar) to maintain indentation and readability. When you post about an error, at least indicate which line raises the error. Something is probably misspelled; perhaps your userform name or one of the referenced controls.

BTW, EmployeeName is a Variant and not a String because it's not explicitly declared. Perhaps you do know and that is intentional.
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,571
Members
449,173
Latest member
Kon123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top