Automated Student Mark Sheet

Marksheet Automation

In this article, we will learn to automate Microsoft Word from Excel with the help of Visual Basic Language. To learn the Word Automation, we will consider a very practical example i.e. Creating Student’s Mark Sheet in MS Word from Excel Table.

If you find that you are constantly copying and pasting data into Microsoft Word in a specific format then you can use the code and logic, which we are going to use here.

Before walking through the macro, it is important to go over a few steps.

Please create a Word file for Students mark sheet as mentioned in below image or download the template used in this tutorial.

Once you create or download the word file, you need to create bookmarks tagging the location where you want your Excel data to be copied.

In current word file, we need total 17 bookmarks to transfer Student Name, Registration Number, Program Name, Examination Date, Grade, Statistics Marks, Statistics Result, Excel Marks, Excel Result, VBA Marks, VBA Result, SQL Marks, SQL Result, Power BI Mark, Power BI Result, Grand Total Marks and Percentage.

Insert Bookmarks
Bookmark Fields Highlighted with red

To create a bookmark in a Word document, place your cursor where you want the bookmark then go to Insert Tab and select Bookmark available under the Links group. This will open the Bookmark dialog box where you can provide the name of bookmark and click on Add button.

Let us follow the same step as mentioned above and create bookmark for ‘Name’.

Steps to Insert Bookmarks
Steps to Insert Bookmarks

In the same way, just create rest of the 16 Bookmarks required for this automation.

Please use the below mentioned Bookmarks name. We will use these names in VBA code while doing automation.

  1. Name
  2. Registration_Number
  3. Program_Name
  4. Examination_Date
  5. Grade
  6. Statistics_Marks
  7. Statistics_Result
  8. Excel_Marks
  9. Excel_Result
  10. VBA_Marks
  11. VBA_Result
  12. SQL_Marks
  13. SQL_Result
  14. PowerBI_Marks
  15. PowerBI_Result
  16. GrandTotal
  17. Percentage

Once, you create all the Bookmarks save the word file in the name ‘Marksheet Template.docx‘ at the same location where you are going to keep MS Excel file. Now, close the file after saving it.

Now, open the Excel Application and create a blank worksheet. Save the file with the name ‘Automating Word from Excel.xlsm’ in the same folder where you have kept Word file.

Create the table with required data as mentioned in below image. Please keep the cell reference as it is otherwise your code will not work (if you are following the same example).

Now, insert a rounded rectangle and give the caption as ‘Prepare Marksheet’. We will assign macro on this button to create mark sheet once coding will be done.

Prepare Excel File and Table
Prepare Excel File and Table

Let us jump to Visual Basic Application Window to start coding. To open VBA Window, go to Developer Tab and Click on Visual Basic button available under Code group.

Go To Visual Basic Window
Go To Visual Basic Window

In Visual Basic window, insert a blank module. Module would be required to write the code.

To insert a module, click on Insert Menu and then select Module.

Insert a Blank Module
Insert a Blank Module

As we are going to automate MS Word from Excel hence, we need to provide the reference of MS Word Object library. To add the reference, click on Tools menu and then select References…

In references window, select ‘Microsoft Word 16.0 Object Library’ from the available references and then click on Okay.

Add Microsoft Word 16.0 Object Library
Add Microsoft Word 16.0 Object Library

Once you done with adding references then double click on Module1 to open the code window.

Start Coding
Start Coding

In Code window, just copy and paste the below code.

Now move to Excel Application and assign the macro on button available on top of the table.

Assign Macro
Assign Macro

You can test this application with the data available in table.

Download Excel and Word files used in this tutorial.

LEAVE A REPLY

Please enter your comment!
Please enter your name here