MS Word
The MS Word functions allow you to retrieve data from, and write data to, MS Word files.
The file on which the function is to be run must not be open in Word when the function is performed.
The functions are divided into two groups, With Word and Without Word:
The difference between the two sets of functions is as follows:
-
With Word
These functions do require that Word be installed on the machine on which the solution is being run. Word is opened every time one of these functions is performed. These functions therefore take longer to perform than the basic functions.
-
Without Word
These functions do not require that Word be installed on the machine on which the solution is being run. The function is performed without opening Word and is therefore performed very quickly. These functions are valid only for Word files generated using Office 2007 onwards (i.e. that have .DOCX extensions).
MS Word Functions - With Word
(Available from version 7.0 onwards.)
These functions do require that Word be installed on the machine on which the solution is being run. Word is opened every time one of these functions is performed. These functions therefore take longer to perform than the basic functions.

Adds the elements in a text list to the beginning of a Word document and saves the file in a specified text format.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
source full path |
Text |
The full path (including file name) of the Word file to open, including its extension For example: c:/temp/MyWordFile.docx |
text |
List of Text |
List of the texts to add to the Word document. |
target full path w/o extension |
Text |
Name and path of the document to save, without its file extension. For example: c:/temp/AddTextChangeFormat |
file type |
Text |
The format in which to save the document. Use the formats listed for Microsoft's WdSaveFormat Enum. For example: wdFormatXPS (for XPS format) or wdFormatRTF (for RTF format) |
Returns
Nothing
Example
In this example, a text string such as Dear Sir, is written to the top of the existing file at c:/temp/Sample_WithWord.docx. (The text string is made up of three components: Sir, a variable called Title, and a comma.)
The file is saved as c:/temp/Sample_asRTF.rtf. To save the file in RTF format, the format wdFormatRTF is specified.
The original Word file is shown below.
The generated RTF file is shown below.

Adds the list of text at the beginning of a Word document, and saves the document.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
source full path |
Text |
The full path (including file name) of the Word file to open, including its extension For example: c:/temp/MyWordFile.docx |
textuals |
List of Text |
List of the texts to add to the Word document. |
Returns
Nothing.
Example
This example opens the Test.docx file, adds the list of text specified in the LVText001 list variable, and saves the document.

Adds the values of the text to the beginning of a Word document and saves it as a different Word document.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
source full path |
Text |
The full path (including file name) of the Word file to open, including its extension For example: c:/temp/MyWordFile.docx |
text |
List of Text |
List of the texts to add to the Word document. |
target full path |
Text |
The full path (including file name) of the Word file to save, including its extension |
Returns
Nothing.
Example
This example opens the Test.docx file, adds the list of text specified in the LVText002 list variable, and saves the document as NewDoc.docx.

Inserts the specified text values into the bookmarks of a specified Word document (full name) and saves the file.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
wordDocumentToOpen |
Text |
Name of the Word document to open. |
textuals |
List |
List of text values to add to the bookmarks. |
bookmarks |
List |
List of bookmarks. |
Returns
Nothing.
Example
This example opens the Test.docx Word document, and sets the text values defined in the list variable LVText001 into the bookmarks defined in the list variable LVText002.
Parameters

Inserts the specified text values into the bookmarks of a specified Word document (full name), and saves the Word document with a new name.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
wordDocumentToOpen |
Text |
Name of the Word document to open. |
textuals |
List |
List of text values to add to the bookmarks. |
bookmarks |
List |
List of bookmarks. |
wordDocumentToSave |
Text |
Name of the target Word document. |
Returns
Nothing.
Example
This example opens the Test.docx Word document, sets the text values defined in the list variable LVText001 into the bookmarks defined in the list variable LVText002, and saves the document as NewDoc.docx.

Retrieves the name of the active Word document.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
none |
|
|
Returns
Returns the Word document name as text.
Example
This example returns the active Word document name into the text variable SVText001.

Retrieves a list of field names in a specified Word document, by the document full name.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
doc_name |
Text |
Name of the Word document. |
Returns
Returns the field names in the specified Word document as a list.
Example
This example returns the field names in the Word document Test,docx, into the list variable LVText002.

Retrieves the value from a specified field in a specified Word document.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
doc_name |
Text |
Name of the Word document. |
field_name |
Text |
Name of the field. |
Returns
Returns the field value as text.
Example
This example returns the value of the field Author from the Test.docx word document, into the text variable SVText001.

Retrieves the list of currently open Word document names.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
none |
|
|
Returns
Returns the names of Word documents as a list.
Example
This example returns the names of currently open Word documents into the list variable LVText002.
MS Word Functions - Without Word
(Available from version 7.1 onwards.)
These functions do not require that Word be installed on the machine on which the solution is being run. The function is performed without opening Word and is therefore performed very quickly. These functions are valid only for Word files generated using Office 2007 onwards (i.e. that have .DOCX extensions).
Example Files
An individual example is provided for each function described below.

To view the sample project:
-
Download the ZIP file of the sample project here.
-
Copy the resx and dproj files to the folder%AppData%/Nice_Systems/AutomationStudio/Projects.
-
Copy the docx file to the folder c:/temp.
-
Open the project MSOffice_Word in Automation Studio. Each workflow is named with the name of the function it demonstrates.
Functions

Adds specified text at the end of a Word document. The text is added at the start of a line below the existing text.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
full path |
text |
The full path (including file name) of the Word file |
text |
text |
The text to append to the Word document |
Returns
Nothing
Example
This example appends the text Lorem ipsum dolor sit amet to the sample file at C:/Temp/SampleFile.docx.
The Word document is shown below:
Before:
After:

Retrieves all text from a Word document.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
full path |
text |
The full path (including file name) of the Word file |
Returns
Returns the text of the Word document in text format
Example
This example retrieves the text in the sample file at C:/Temp/SampleFile.docx, and stores it in the text variable text_response.
When executed, the variable text_response is set to the text in the Word document.

Finds all instances of specified text within a Word document and replaces all instances with specified replacement text. This function is case sensitive.
The formatting of the replacement text is the same as that of the replaced text.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
full path |
text |
The full path (including file name) of the Word file |
find text |
text |
The text to find |
replacement text |
text |
The replacement text |
If the replacement text includes line breaks, add the code <w:br /> to the end of each line.
For example, instead of:
Enter:
If you do not include the code <w:br />, the text will be entered on a single line.
Returns
Nothing
Example
This example replaces the word fox in the sample file at C:/Temp/SampleFile.docx with the word cat.
The Word document is shown below:
Before:
After: