In this blog, I will try to cover how to get rid of Mail Merge by using the sample Excel VBA code. We all know how to do the mail merge in MS Word. But today I will discuss on mail merge in Excel. The data in your spreadsheet and you want to send the mail to the multiple people at a time.
For example, in your spreadsheet, you have data like Firstname, Lastname, Email-id, Date of Birth, and phone numbers. You have a long list like this. Now every day you need to check the date of birth and send the email to the associated person.
Now I can show you how to write a simple VBA code that will check the date of birth and then send the email using either email or from your outlook.
Let’s assume you have the sample the data like below in a sheet called “DataSheet”
Excel VBA Macros for Non-Coders

Do you find VBA Macros scary? Did you miss any job opportunity because of it? Get started today with our eBook guide on using – Excel VBA Macros. 140 pages of rich visuals. Download now.

It’s a simple data set of the employee. We need to check whose birth date is today and then you need to send an email.
Now I will show you how to write a simple that will check the birthday of the employees and sent them an email from your outlook or Gmail taking the email id from the sheet.
How to Automate Mail Merge through VBA in Microsoft Excel | VBA
- We will create a simple template for out later reference. I have added a new sheet and changed the name of the sheet as “Mail Merge”.
- Then I have created a simple template like below.

I have created this template in Excel using page layout. I have inserted a picture in the corner which is downloaded from the internet. In future, if you want to take the print out of the birthday boys it will work.
Now you need to write the code. Press Alt +F11 to go to VBA page. Then Click on insert and then click on Module.

After creating the new module copy the below code and then paste the below code in the module. We will catch the code one by one line later. This code is applicable when you are sending it from your Gmail id.
Before pasting the code in the module, make sure that Microsoft CDO for windows 2000 library checkbox is on. To check the same just follow the below steps.
- Step 1: Click on Tools
- Step 2: Then go to References
- Step 3: Microsoft CDO for windows 2000 library

If this is not checked then please tick the box and then press OK.
Then you need to paste the below code in the module. Mail Merge through VBA in Microsoft Excel
You need to change the references as per your data. In my case date of birth is in D column and email id is present in G Column. And in the H column, I have checked where the date of birth is today or not. Mail Merge through VBA in Microsoft Excel.
Now go back to the Mail Merge sheet and then insert a shape. And then right-click on it and then click on assign macros and select the name the procedure you have pasted just now.

Now if you click on the shape then it will call your Sendmail procedure and it will send an email from your Gmail account. But before that, you need to give a valid user name and your Gmail password.
If your less secure app is off in your Gmail account then probably you will not able to deliver the email. So before hit the button go back to your Gmail account and set less secure app is on.

Mail Merge Code for using in Outlook:
This code will help you to send the email from outlook:
Further, let me know if you created a variant for this? Happy to discuss new ideas 🙂 Mail Merge through VBA in Microsoft Excel
Excel VBA Macros for Non-Coders

Do you find VBA Macros scary? Did you miss any job opportunity because of it? Get started today with our eBook guide on using – Excel VBA Macros. 140 pages of rich visuals. Download now.