Category Archives: VBA for Word

Access Word Objects through Excel VBA

In this article, we will see how to access the various word objects using VBA in Excel and insert data from Excel to Word. This has many practical applications such as when you have to fill out a form multiple times with data from Excel or

No Thumbnail

Word VBA OverFlow Error When Multiplying/Adding Integers

It might have occurred to you when working with integers in VBA for Word that you get the following error: This error generally occurs when you are doing arithmetic operations on integer values that result in: Values larger than 32767 Values smaller than -32768 This is because integers only

No Thumbnail

Word VBA, Assign Shortcut Key to Macro

This article explains how you can assign a shortcut key or key combination to a macro. – Step 1: Press the “File” button on the top left of the word application, then click on options:   Note: In word 2007, there will be an “Office

No Thumbnail

Word VBA, Delete Empty Rows From Tables

One of the things a lot of word users encounter while working in word, are empty rows in tables. In this article I will provide a code that will delete all empty rows from all tables in the document. – Delete Empty Rows From Single Table: In

No Thumbnail

VBA, Write Excel Values to Word Document

In this article I will explain how you can write data from an excel workbook to a word document. The first step in doing this is to determine where the code is going to be written. There are 3 options: In the excel workbook In the

No Thumbnail

Word VBA, Delete Equations

In order to delete an equation using VBA for word, you will have to know its index. Equations are referenced through the OMaths collection. In the example the below the first equation in the document is removed along with all its text: OMaths.Item(1).Range.Select Selection.Delete Before: After:

No Thumbnail

Word VBA, Get Current Line Number

Using the code below you can get the current line the cursor is on: Sub main() Dim intCurrentLine As Integer intCurrentLine = _ Selection.Range.Information(wdFirstCharacterLineNumber) MsgBox (intCurrentLine) End Sub Note: The current page number is relative to the page. That means the line number