
If you find that you are continuously copying and pasting information into Microsoft Word in a particular format then you may use the code and logic, which we are going to use here.
Before walking via the macro, it is critical to go over some steps.

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 the 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.

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

In the same way, just create the 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.
- Name
- Registration_Number
- Program_Name
- Examination_Date
- Grade
- Statistics_Marks
- Statistics_Result
- Excel_Marks
- Excel_Result
- VBA_Marks
- VBA_Result
- SQL_Marks
- SQL_Result
- PowerBI_Marks
- PowerBI_Result
- GrandTotal
- 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 the required data as mentioned in the 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 a mark sheet once coding will be done.

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.

In the Visual Basic window, insert a blank module. A module would be required to write the code.
To insert a module, click on Insert Menu and then select 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 reference window, select ‘Microsoft Word 16.0 Object Library’ from the available references and then click on Okay.

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

In Code window, just copy and paste the below code.
Now move to Excel Application and assign the macro on the button available on top of the table.

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

No comments: