Tag Archives: Word

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:

Word Skip Record If Rule (Mail Merge)

In this article I will explain the Skip Record If Rule used in Mail Merge. – What is it? The Skip Record If Rule compares the value of a field with a certain value. If the comparison returns true, the current record will not be merged. Example: Consider

No Thumbnail

Word, Remove Fill in Rules

In order to remove the Fill in Rules in a document: Step 1: Press Alt + F9. Step 2: Look for FILLIN fields and remove them: See also: Word Ask Rule (Mail Merge) Microsoft Office Support, Field Codes: Ask Field If you need assistance with your code, or

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

No Thumbnail

VBA, Word Table Insert/Remove Rows/Columns

In this article I will explain how you can add and delete rows and columns from tables in a word document using VBA. Every word document has a Tables collection The first step in working with a table in VBA for word is to determine the

No Thumbnail

Word VBA, Get Current Page Number

Using the code below you can get the current page number the cursor is on: Sub main() Dim intCurrentLine As Integer intCurrentLine = _ Selection.Range.Information(wdActiveEndPageNumber) MsgBox (intCurrentLine) End Sub In the figure below the cursor is located at page 10: Result after running the code: See also:

No Thumbnail

VBA, Automating Word From Excel

There are 2 methods for initiating a word application from excel using VBA: Early Binding Late Binding Basically in early binding we define what object we are creating reference to before program execution. In late binding, the program won’t know what we are creating reference to

No Thumbnail

Word VBA, Move Cursor to End of Line

Using the code snippet below you can move the cursor to the end of the Line: Selection.EndKey Unit:=wdLine Assume the cursor is somewhere in the middle of a line: Result after using the code above:   See also: Word VBA, Move Cursor to Start of Document Word

No Thumbnail

Word VBA, Move Cursor to End of Document

Using the code snippet below you can move the cursor to the end of the document: Selection.EndKey Unit:=wdStory Assume the cursor is somewhere in the middle of page 1: Result after using the code above: See also: Word VBA, Move Cursor to Start of Document Word VBA,

No Thumbnail

Word VBA, Print as PDF

In this article I will explain how you can use VBA for word to save a document as a pdf. – Basics: The basic code for saving a word document as a pdf can be seen below: ActiveDocument.ExportAsFixedFormat OutputFileName:= _ “D:StuffBusinessTempPDFName.pdf”, _