# \*OBJ/WORD: PxPlus Word Object

> Source: https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object

The **PxPlus Word** object simplifies the use of the Word.Application extended object. This object consists of various properties and methods that make it easier to interact with Word documents. See **[Properties and Methods](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#properties)**.

The Word object allows more than one Word document to be opened at one time.

*(The PxPlus Word object was added in PxPlus 2017.)*

***Instantiating the Word Object***

To ***instantiate*** the Word object using the handle **word_obj** (where **word_obj** could be any numeric variable), enter the following command:

```
word_obj=NEW("*obj/word")
```

If the object should bind to a running instance of Word, you may pass the **\[RUNNING\]** option for the **[DEF_OBJECT](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/referencing-a-com-object#running)** directive by entering the command as:

```
word_obj=NEW("*obj/word","running")
```

***Where:***

"running" is case insensitive.

*(The ability to instantiate the Word object by passing the \[RUNNING\] parameter was added in PxPlus 2025.)*

If the object should bind to a running instance of Word, if possible, but create a new instance otherwise, you may pass the **\[RUNNING OR NEW\]** option for the **[DEF_OBJECT](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/referencing-a-com-object#runningnew)** directive by entering the command as:

```
word_obj=NEW("*obj/word","running or new")
```

***Where:***

"running or new" is case insensitive.

*(The ability to instantiate the Word object by passing the \[RUNNING OR NEW\] parameter was added in PxPlus 2025.)*

To access any of the available properties and/or methods, the Word object handle (**word_obj**) is used, followed by an **'** *(apostrophe)* and the property or method (with the desired parameters).

***Examples:***

```
doc=word_obj'ACTIVE_DOCUMENT

retVal=word_obj'SetDocument(3)
```

Note:  
If you are familiar with the Word.Application extended object, all existing properties and methods will continue to be accessible by referencing the WORD property.  
  
*Example:*  
  
C=word_obj'WORD'DOCUMENTS'Count

***When an Error is Encountered***

In case of method failure, the **[ERROR](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/extended-objects#error)** object may be useful in getting more information about the last error encountered.

***Example:***

If Word is unable to set the active document in the previous example because there are not three documents in the collection, retVal will be equal to '0'. Checking the **Description$** property of the **[ERROR](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/extended-objects#error)** object may also provide more information:

```
PRINT word_obj'ERROR'Description$

The requested member of the collection does not exist.
```

***Global Named Constants***

The Word Application makes use of hundreds of global named constants. If required, these constants may be accessed by using the **[PVXCONSTANTS](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/extended-properties-and-methods#pvxconstants)** object, which has been defined as a property called **WCONSTANTS**. See **[\*CONSTANTS](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/extended-objects#constants)**.

***Example:***

```
PRINT word_obj'WCONSTANTS'wdAlertsMessageBox     (should return -2)
```

## Properties and Methods

The ***properties*** used by the Word object are listed below.

| **Property** | **Description** |
| --- | --- |
| **ACTIVE_DOCUMENT** | ***(Read Only)*** Handle to the active document object. This property is set by using the **[SetDocument](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#setdocument)** method and corresponds to the WORD'ActiveDocument value. |
| **CASE_SENSITIVE_SEARCH** | Defaults to '0' for case insensitive searches. Set to '1' for case sensitive searches.  <br>  <br>See **[Find](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#find)**, **[FindInsert](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findinsert)**, **[FindReplace](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findreplace)**, **[FindReplaceAll](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findreplaceall)**, **[FindSetColor](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findsetcolor)** and **[FindSetFont](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findsetfont)** methods below. |
| **DISPLAY_ALERTS** | Allows suppression of Word message boxes. Defaults to ***Off*** ('0'). |
| **DOCUMENTS_COUNT** | ***(Read Only)*** Number of documents opened. This property corresponds to the WORD'DOCUMENTS'Count value. |
| **ERROR** | ***(Read Only)*** Handle to Word **[ERROR](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/extended-objects#error)** object. Can be used to display the last error message via the **Description$** property. |
| **INSERT_BEFORE** | Defaults to '0' so that the **Insert** (see **[FindInsert](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findinsert)** below) will insert text ***after*** the position located with the **Find** method.  <br>  <br>To insert text ***before*** the position located with the **Find** method, set this value to '1'. |
| **KEEP_VISIBLE** | Set to a non-zero value to keep the Word application active and visible when the PxPlus Word Object is dropped. Has no effect if the **VISIBLE** property has not been set. Defaults to ***Off*** ("0").<br>*(The KEEP_VISIBLE property was added in PxPlus 2020.)* |
| **SEARCH_FORWARD** | Defaults to '1' so that the **[FindReplaceAll](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findreplaceall)** and the various **Find** methods (see **[Find](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#find)**, **[FindInsert](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findinsert)**, **[FindReplace](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findreplace)**, **[FindSetColor](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findsetcolor)** and **[FindSetFont](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#findsetfont)**) will search from the beginning of the document to the end.  <br>  <br>To begin at the end of the document (i.e. find the last occurrence of a string), set this value to '0'. |
| **VISIBLE** | Allows the Word application to be made visible. Defaults to ***Off*** ('0'). |
| **WCONSTANTS** | ***(Read Only)*** Handle to the Word **[CONSTANTS](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/extended-objects#constants)** object. |
| **WORD** | ***(Read Only)*** Handle to the main Word object.<br>Note:  <br>This property *cannot be set* but is provided to allow access to all of the properties and methods in the Word Application. |

The ***methods*** used by the Word object are listed below. To make it easier to locate information for a particular method, this list has been broken into the following smaller groups:

|  |  |  |
| --- | --- | --- |
|  | **[Document Methods](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#methodsdoc)** | For creating, setting, printing, saving and closing a document |
|  | **[Paragraph Methods](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#methodspara)** | For creating, inserting, reading and deleting a paragraph |
|  | **[Sentence Methods](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#methodssentence)** | For creating, inserting, reading and deleting a sentence |
|  | **[Text Methods](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#methodstxt)** | For finding, replacing, inserting and setting text color/font |

***Common Parameters***

The following is a list of some of the common parameters used by multiple methods of the Word object:

| **Parameter** | **Description** |
| --- | --- |
| *document* | 1-based index number of the Word document. |
| *document_name$* | Simple document name without the full path (e.g. *"test_document.docx"*). |
| *path$ **or** document_path$* | Full path name for the document (e.g. *"c:/application/test_document.docx"*). |

***Document Methods***

| **Document Methods** | **Description** |
| --- | --- |
| AppendFile(*path$***)**<br>AppendFile(*path$*,*document*)<br>AppendFile(*path$*,*document_name$***)** | Appends the file defined as *path$* at the end of the document specified by either an index number or a simple document name. If no document is specified, the active document is assumed.<br>Returns '1' if successful.<br>Returns '0' if Word was unable to locate the document specified or the file indicated by *path$* is invalid.<br>*(The AppendFile method was added in PxPlus 2019.)* |
| **CloseDocument( )**<br>CloseDocument(*document*)<br>CloseDocument(*document_name$***)** | Closes the document specified by either an index number or a simple document name. If no document is specified, the active document will be closed.<br>Note:  <br>Any unsaved changes in a document are *not* saved if the [DISPLAY_ALERTS](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#displayalerts) property is set to '0' (zero), the default value. To prompt the user about saving the changes, set DISPLAY_ALERTS to '1'. To ensure that all changes are saved and minimize user intervention, be sure to save the document prior to closing.<br>Returns '1' if successful.  <br>  <br>Returns '0' if Word was unable to locate or close the document. |
| **CloseDocuments( )** | Closes all open documents. This method is called automatically when the Word object is dropped.<br>Note:  <br>Any unsaved changes in the documents are *not* saved if the [DISPLAY_ALERTS](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#displayalerts) property is set to '0' (zero), the default value. To prompt the user about saving the changes, set DISPLAY_ALERTS to '1'. To ensure that all changes are saved and minimize user intervention, be sure to save the documents prior to closing.<br>Returns '1' if successful.<br>Returns '0' if Word was unable to close the documents. |
| CreateDocument(*path$***)** | Creates a new Word document (*path$*). The *path$* parameter may be either a simple or full pathname. The new document is opened and becomes the **[ACTIVE_DOCUMENT](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#activedocument)**.<br>If the *path$* parameter is null, the document is named according to the Word default (e.g. *Document1.docx*).<br>Warning!  <br>In case of a pre-existing file named path$, the previous version will be *overwritten with no prompt* to the user.<br>Returns '1' if successful.<br>Returns '0' if Word was unable to add the document. |
| InsertFile(*path$***)**<br>InsertFile(*path$*,*para_num*)<br>InsertFile(*path$*,*para_num*,*document*)<br>InsertFile(*path$*,*para_num*,*document_name$***)** | Allows you to merge two files together by inserting a specified file into a given location (paragraph number) in a particular document.<br>Inserts the file defined as *path$* in the document specified by either an index number or a simple document name. The file will be inserted beginning as paragraph number *para_num*. If no document is specified, the active document is assumed.<br>If *para_num* is not specified or is set to 0, the file will be inserted beginning at paragraph 1. If *para_num* is larger than the current number of paragraphs, the paragraph will be inserted before the last paragraph.<br>Alternatively, to insert a file at the very end of the document, use one of the **[AppendFile( )](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#appendfile)** methods.<br>Returns '1' if successful.<br>Returns '0' if Word was unable to locate the document specified or the file indicated by *path$* is invalid.<br>*(The InsertFile method was added in PxPlus 2019.)* |
| OpenDocument(*path$***)** | Opens the Word document located at pathname *path$*.<br>After opening a document, the **[ACTIVE_DOCUMENT](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#activedocument)** property is set to the document object corresponding to the document just opened.<br>Note:  <br>When opening more than one document, the last document opened is always considered to be document index 1. All of the previously opened document indexes move up one index higher.<br>Returns '1' if successful.  <br>  <br>Returns '0' if the path specified was invalid or if Word was unable to open the document. |
| **PrintDocument( )**<br>PrintDocument(*document*)<br>PrintDocument(*document_name$***)** | Prints the document specified by either an index number or a simple document name. If no document is specified, the active document is printed.<br>To print all of the documents currently opened, pass a *document_name$* of '**ALL**' (case insensitive).<br>Note:  <br>No printer dialog will be displayed. The document will be printed to the default Word printer with the default settings.<br>Returns '1' if successful.  <br>  <br>Returns '0' if Word was unable to locate the document. |
| SaveAsDocument(*document_path$***)**<br>SaveAsDocument(*document_path$,document*)<br>SaveAsDocument(*document_path$,document_name$***)** | Used to save a document to a different location or with a different file format.<br>Saves the document specified (by either an index number or a simple document name) with the pathname provided. If no document is specified, the active document is saved. If a full pathname is not provided, the document will be saved in the default Word document folder.<br>The format used to save the document is determined by the extension specified in the *document_path$*. Supported extensions are listed below (in alphabetical order).<br>\|  \|  \|  \|  \|  \|<br>\| --- \| --- \| --- \| --- \| --- \|<br>\|  \| *.doc* \| Word 97 - 2003 Document \| *.mht, .mhtml* \| Single File Web Page \|<br>\|  \| *.docm* \| Word Macro-Enabled Document \| *.odt* \| Open Document Text \|<br>\|  \| *.docx (or null)* \| Word Document \| *.pdf* \| PDF \|<br>\|  \| *.dot* \| Word 97 – 2003 Template \| *.rtf* \| Rich Text Format \|<br>\|  \| *.dotm* \| Word Macro-Enabled Template \| *.txt* \| Plain Text (preserve line breaks) \|<br>\|  \| *.dotx* \| Word Template \| *.xml* \| Word XML Document \|<br>\|  \| *.htm, .html* \| Web Page \| *.xps* \| XPS Document \|<br>Returns '1' if successful.  <br>  <br>Returns '0' if the pathname is invalid, already exists, or if Word was unable to save the document.<br>*(Support for other file formats was added in PxPlus 2018.)* |
| **SaveDocuments( )** | Saves all currently opened documents.<br>Returns '1' if successful.  <br>  <br>Returns '0' if Word was unable to save any of the documents.  <br>  <br>Returns '-1' if Word was only able to save some of the documents successfully. |
| **SaveDocument( )**<br>SaveDocument(*document*)<br>SaveDocument(*document_name$***)** | Saves the document specified by either an index number or a simple document name. If no document is specified, the active document is saved.<br>Returns '1' if successful.  <br>  <br>Returns '0' if Word was unable to locate or save the document. |
| SetDocument(*document*)<br>SetDocument(*document_name$***)** | Sets the active document object **[ACTIVE_DOCUMENT](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#activedocument)** to the document specified by either an index number or a simple document name (e.g. *sample_doc.docx*).<br>Returns '1' if successful.  <br>  <br>Returns '0' if Word was unable to locate the document. |

***Paragraph Methods***

| **Paragraph Methods** | **Description** |
| --- | --- |
| AppendParagraph(*para_text$***)**  <br>AppendParagraph(*para_text$*,*document*)  <br>AppendParagraph(*para_text$*,*document_name$***)** | Appends the text defined as *para_text$* as a new paragraph at the end of the document specified by either an index number or a simple document name. If no document is specified, the active document is assumed.  <br>To insert a paragraph with no text, set *para_text$=""*.  <br>Returns '1' if successful.  <br>Returns '0' if Word was unable to locate the document specified.  <br>*(The AppendParagraph method was added in PxPlus 2019.)* |
| InsertParagraph(*para_text$***)**  <br>InsertParagraph(*para_text$*,*para_num*)  <br>InsertParagraph(*para_text$*,*para_num*,*document*)  <br>InsertParagraph(*para_text$*,*para_num*,*document_name$***)** | Inserts the text defined as *para_text$* as a new paragraph added to the document specified by either an index number or a simple document name. The paragraph will be inserted as paragraph number *para_num*. If no document is specified, the active document is assumed.  <br>If *para_num* is not specified or is set to 0, the paragraph will be inserted as paragraph 1. If *para_num* is larger than the current number of paragraphs, the paragraph will be inserted as the last paragraph.  <br>Alternatively, to insert a paragraph at the very end of the document, use one of the **AppendParagraph(** **)** methods.  <br>To insert a paragraph with no text, set *para_text$=""*.  <br>Returns '1' if successful.  <br>Returns '0' if Word was unable to locate the document specified.  <br>*(The InsertParagraph method was added in PxPlus 2019.)* |
| ReadParagraph$(*para_num*)  <br>ReadParagraph$(*para_num,document*)  <br>ReadParagraph$(*para_num,document_name$***)** | Reads the contents of the paragraph numbered *para_num* in the document specified by either an index number or a simple document name. If no document is specified, the active document is assumed.  <br>A *para_num* value of less than 1 will read the first paragraph.  <br>Returns a string containing the text for the paragraph specified if successful.  <br>Returns '0' if Word was unable to locate the document specified or the paragraph number *para_num* does not exist.  <br>*(The ReadParagraph$ method was added in PxPlus 2019.)* |
| DeleteParagraph(*para_num*)  <br>DeleteParagraph(*para_num,document*)  <br>DeleteParagraph(*para_num,document_name$***)** | Deletes the paragraph numbered *para_num* from the document specified by either an index number or a simple document name. If no document is specified, the active document is assumed.  <br>A *para_num* value of less than 1 will delete the first paragraph.  <br>Returns '1' if successful.  <br>Returns '0' if Word was unable to locate the document specified or the paragraph number *para_num* does not exist.  <br>*(The DeleteParagraph method was added in PxPlus 2019.)* |

***Sentence Methods***

| **Sentence Methods** | **Description** |
| --- | --- |
| AppendSentence(*sent_text$***)**  <br>AppendSentence(*sent_text$,document*)  <br>AppendSentence(*sent_text$,document,name$***)** | Appends the text defined as *sent_text$* as a new sentence (or sentences) at the end of the document specified by either an index number or a simple document name. If no document is specified, the active document is assumed.  <br>Returns '1' if successful.  <br>Returns '0' if Word was unable to locate the document specified.  <br>*(The AppendSentence method was added in PxPlus 2019.)* |
| InsertSentence(*sent_text$***)**  <br>InsertSentence(*sent_text$,sent_num*)  <br>InsertSentence(*sent_text$,sent_num,document*)  <br>InsertSentence(*sent_text$,sent_num,document_name$***)** | Inserts the text defined as *sent_text$* as a new sentence added to the document specified by either an index number or a simple document name. If no document is specified, the active document is assumed.  <br>If *sent_num* is set to 0, the sentence will be inserted as sentence 1. If *sent_num* is larger than the current number of sentences, the sentence will be inserted as the last sentence.  <br>Alternatively, to insert a sentence at the very end of the document, use one of the **AppendSentence(** **)** methods.  <br>Returns '1' if successful.  <br>Returns '0' if Word was unable to locate the document specified.  <br>*(The InsertSentence method was added in PxPlus 2019.)* |
| ReadSentence$(*sent_num*)  <br>ReadSentence$(*sent_num,document*)  <br>ReadSentence$(*sent_num,document_name$***)** | Reads the contents of the sentence numbered *sent_num* in the document specified by either an index number or a simple document name. If no document is specified, the active document is assumed.  <br>A *sent_num* value of less than 1 will read the first sentence.  <br>Returns a string containing the text for the sentence specified if successful.  <br>Returns '0' if Word was unable to locate the document specified or the sentence number *sent_num* does not exist.  <br>*(The ReadSentence$ method was added in PxPlus 2019.)* |
| DeleteSentence(*sent_num*)  <br>DeleteSentence(*sent_num,document*)  <br>DeleteSentence(*sent_num,document_name$***)** | Deletes the sentence numbered *sent_num* from the document specified by either an index number or a simple document name. If no document is specified, the active document is assumed.  <br>A *sent_num* value of less than 1 will delete the first sentence.  <br>Returns '1' if successful.  <br>Returns '0' if Word was unable to locate the document specified or the sentence number *sent_num* does not exist.  <br>*(The DeleteSentence method was added in PxPlus 2019.)* |

***Text Methods***

| **Text Methods** | **Description** |
| --- | --- |
| Find(*find$***)**<br>Find(*find$,document*)<br>Find(*find$,document,instance*)<br>Find(*find$,document_name$***)**<br>Find(*find$,document_name$,instance*) | Determines if a particular string *(find$)* exists in a document specified by either an index number or a simple document name. If no document is specified, the Find will check the active document.<br>Searches are case insensitive by default. For case sensitive searches, set the **[CASE_SENSITIVE_SEARCH](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#casesearch)** property to '1'.<br>Returns '1' if the text *find$* was found.  <br>  <br>Returns '0' if Word was unable to locate the document or if the text *find$* was not found in the document. |
| FindInsert(*find$,insert$***)**<br>FindInsert(*find$,insert$,document*)<br>FindInsert(*find$,insert$,document,instance*)<br>FindInsert(*find$,insert$,document_name$***)**<br>FindInsert(*find$,insert$,document_name$,instance*) | Finds the text defined as *find$* in a document specified by either an index number or a simple document name and inserts the text defined as *insert$* into the document. If no document is specified, the active document is assumed.<br>To perform the Insert on all opened documents, pass a *document_name$* of '**ALL**' (case insensitive).<br>Specify an *instance* value to indicate which occurrence of the *find$* text that the Find is to locate if different from the first occurrence. (e.g. *instance* of 2 refers to second occurrence). If the Find is to begin from the end of the document, set the **[SEARCH_FORWARD](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#searchforward)** property to '0'.<br>By default, the *insert$* text will be inserted immediately following the *find$* text. To insert the *insert$* text before the *find$* text, set the **[INSERT_BEFORE](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#insertbefore)** property to '1'.<br>Returns '1' if successful.  <br>  <br>Returns '0' if the Find was unsuccessful or if Word was unable to locate the document or insert the text. |
| FindReplace(*find$,replace$***)**<br>FindReplace(*find$,replace$,document*)<br>FindReplace(*find$,replace$,document,instance*)<br>FindReplace(*find$,replace$,document_name$***)**<br>FindReplace(*find$,replace$,document_name$,instance*) | Finds the text defined as *find$* in a document specified by either an index number or a simple document name and replaces the *find$* text with the *replace$* text. If no document is specified, the active document is assumed.<br>To perform the Replace on all opened documents, pass a *document_name$* of '**ALL**' (case insensitive).<br>Specify an *instance* value to indicate which occurrence of the *find$* text that the Find is to locate if different from the first occurrence. (e.g. *instance* of 2 refers to second occurrence). If the Find is to begin from the end of the document, set the **[SEARCH_FORWARD](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#searchforward)** property to '0'.<br>Returns '1' if successful.  <br>  <br>Returns '0' if the Find was unsuccessful or if Word was unable to locate the document or replace the text. |
| FindReplaceAll(*find$,replace$***)**<br>FindReplaceAll(*find$,replace$,document*)<br>FindReplaceAll(*find$,replace$,document_name$***)** | Finds the string *find$* and replaces all occurrences with the string *replace$*.<br>When only the *find$* and *replace*$ parameters are passed, the Find/Replace is performed on the active document. Pass either a document index number or a simple document name to perform the Find/Replace on a document other than the active document without changing the **[ACTIVE_DOCUMENT](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#activedocument)** property.<br>To perform the Find/Replace on all opened documents, pass a *document_name$* of '**ALL**' (case insensitive).<br>Searches are case insensitive by default. For case sensitive searches, set the **[CASE_SENSITIVE_SEARCH](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#casesearch)** property to '1'.<br>Searches will replace all occurrences of the *find$* string. The **FindReplace** method can be used to replace a single occurrence of the *find$* string.<br>Returns '1' if successful.  <br>  <br>Returns '0' if Word was unable to perform Find/Replace on any of the documents specified or if the *find$* value was not found.<br>***When finding/replacing on all documents***: Returns '-1' if Word was only able to perform find/replace on some of the documents successfully. |
| FindSetColor(*find$,color_index*)<br>FindSetColor(*find$,color_index,document*)<br>FindSetColor(*find$,color_index,document,instance*)<br>FindSetColor(*find$,color_index,document_name$***)**<br>FindSetColor(*find$,color_index,document_name$,instance*)<br>FindSetColor(*find$,color$***)**<br>FindSetColor(*find$,color$,document*)<br>FindSetColor(*find$,color$,document,instance*)<br>FindSetColor(*find$,color$,document_name$***)**<br>FindSetColor(*find$,color$,document_name$,instance*) | Finds the text defined as *find$* in a document specified by either an index number or a simple document name and sets the color for that text as specified in *color_index* or *color$*. If no document is specified, the active document is assumed.<br>To set the color of the *find$* text on all opened documents, pass a *document_name$* of '**ALL**' (case insensitive).<br>Specify an *instance* value to indicate which occurrence of the *find$* text that the Find is to locate if different from the first occurrence. (e.g. *instance* of 2 refers to second occurrence). If the Find is to begin from the end of the document, set the **[SEARCH_FORWARD](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#searchforward)** property to '0'.<br>The text color may be passed as one of the following:<br>• A color index (numeric)  <br> • An RGB value in the format "RGB(*rrr,ggg,bbb*)" (string)  <br> • A **wdColorIndex** constant such as "wdColorAqua" (string)  <br> • A **wdColor** constant such as "wdPink"   <br> • One of the 16 basic PxPlus named colors such as 'Red', 'Dark Blue' or 'Light Cyan' (string)  <br>  <br>*(RGB values and color constants were added in PxPlus 2019.)*<br>Note:  <br>A Word color index is an integer value ranging from 1 to 16.<br>Returns '1' if successful.  <br>  <br>Returns '0' if the Find was unsuccessful or if Word was unable to locate the document or set the color. |
| FindSetFont(*find$,font$***)**<br>FindSetFont(*find$,font$,document*)<br>FindSetFont(*find$,font$,document,instance*)<br>FindSetFont(*find$,font$,document_name$***)**<br>FindSetFont(*find$,font$,document_name$,instance*) | Finds the text defined as *find$* in a document specified by either an index number or a simple document name and sets the font information (font name, font size, font style) for that text as specified in *font$*. If no document is specified, the active document is assumed.<br>To set the font of the *find$* text on all opened documents, pass a *document_name$* of '**ALL**' (case insensitive).<br>Specify an *instance* value to indicate which occurrence of the *find$* text that the Find is to locate if different from the first occurrence. (e.g. *instance* of 2 refers to second occurrence). If the Find is to begin from the end of the document, set the **[SEARCH_FORWARD](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/word-object#searchforward)** property to '0'.<br>The *font$* variable can pass font name, font size and font style (Bold, Italic, etc.), separated by commas.<br>***Example:***  <br>  <br> *font$*="Arial" sets only the font name.  <br> *font$*="Arial,12" sets the font name and size.  <br> *font$*="Arial,12, Italic" sets the font name and size and adds italics to the text in the range.  <br> *font$*="Arial,12, Bold, Underline-" sets the font name and size, adds bolding and removes any underlining.  <br> *font$*="Arial,12, Regular" sets the font name and size and removes any bolding, italics and underlining.<br>Note:  <br>Valid fontstyle$ values are 'Regular', 'Bold+', 'Bold-', 'Bold' (same as 'Bold+'), 'Italic+', 'Italic-', 'Italic' (same as Italic+), 'Underline+', 'Underline-', 'Underline' (same as 'Underline+') or any combination of these.<br>Returns '1' if successful.<br>Returns '0' if the Find was unsuccessful or if Word was unable to locate the document or set the font.<br>*(Support for removing bolding, italics and underlining was added in PxPlus 2021.)* |

## Example 1: Testing the Word Object

This example tests the Word object.

```
! Test word object
!
! Instantiate object
w=NEW("*obj/word")
!
! Open document
path$="c:\documents\document1.docx"
doc1=w'OpenDocument(path$)
!
! Open another document
path2$="c:\documents\document2.docx"
doc2=w'openDocument(path2$)
!
! Check number of documents open
MSGBOX STR(w'documents_count)
!
! Set document to first document opened
t=w'SetDocument("document2.docx)
!
! Search and Replace on all opened documents
find$="[FirstName]"
replace$=firstName$
test=w'FindReplaceAll(find$,replace$,"all")
!
! Make Word visible
w'Visible=1
!
! Set active document
q=w'SetDocument(2)
!
! find text and set font in active document
w'FindSetFont("Set font on this text","Algerian,18,bold")
!
! find second instance of text and set color index of active document
w'FindSetColor("Sample text",4,0,2)
!
! Find last instance of text and replace with alternate text in test.docx
w'search_forward=0
w'FindReplace("Find Text","Replace text","test.docx",1)
!
! Save active document with another name
w'SaveAsDocument("c:\document\differentdoc.docx")
!
!
DROP OBJECT w
END
```

## Example 2: Using the Word Object in a Template

This example demonstrates using the Word object to replace given placeholders in a template document with variable data:

- The ***promo.docx*** document below acts as the template document.
- The ***PxPlus promo*** program uses the Word object to populate the various pieces of data within the square brackets.

***promo.docx*** ***document:***

![](https://manual.pvxplus.com/migration-assets/403caf0096d1650586bb7f66f77307428afa9d94ab10af21d38a5a5498b98def.png)

***PxPlus promo program:***

```
! promo - Use Word object for mail merge
!
OPEN (HFN,IOL=*)"client"
clients=LFO
!
path$="C:\PVX Plus Technologies\PxPlus version_number\word\"
!
w=NEW("*obj/word")
!
! populate client name and address data
search_fields$="ClientName$"+SEP+"Address1$"+SEP+"Address2$"+SEP+"City$"+SEP+"State$"+SEP+"Country$"+SEP+"ZipCode$"+SEP+"ytdSales"+SEP
SELECT * FROM clients WHERE ytdSales>10000
promo=w'OpenDocument(path$+"promo.docx")
!
ERASE path$+Clientid$+"docx",ERR=*NEXT
!
FOR field$ FROM search_fields$
find$="["+field$+"]"
IF find$="[ytdSales]" THEN replace$="$"+STP(STR(ytdSales:"###,###.00"),"L"," ") ELSE replace$=VIS(field$)
w'case_sensitive_search=1
w'FindReplaceAll(find$,replace$)
NEXT
!
! populate dates
w'FindReplaceAll("[TodaysDate]",DTE(0:"%Ml %D,%Y"))
w'FindReplaceAll("[YearDate]",DTE(0:"%Y"))
!
! highlight '25% off coupon'
W'FindSetColor("25% off coupon","red")
!
w'SaveAsDocument(path$+ClientId$)
w'PrintDocument(1)
w'CloseDocument(1)
!
NEXT RECORD
!
DROP OBJECT w
CLOSE (clients,ERR=*NEXT)
!
END
```

## See Also

**[PxPlus Excel Object](https://manual.pvxplus.com/pxplus-user-guide/external-components/pxplus-com-support/excel-object)**  
**[Google Workspace Objects](https://manual.pvxplus.com/google-workspace-objects/introduction)**
