Skip to main content

Open Word

Opens an existing Word document or creates a new blank document.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing the node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • File Path - Path to the Word document to open. Leave empty to create a new blank document in memory. When provided, must be a valid path to an existing .docx file.

Output

  • Out File Descriptor - Unique identifier for the opened or created document. This file descriptor is used by other Word nodes to reference the document. Default variable name is word_fd.

How It Works

The Open Word node is flexible and can work in two modes:

Mode 1: Open Existing Document

  1. Validates the provided file path
  2. Checks if the file exists at the specified location
  3. Opens the Word document
  4. Generates a unique file descriptor
  5. Returns the file descriptor for use with other Word nodes

Mode 2: Create New Document (when path is empty)

  1. Creates a new blank Word document in memory
  2. Generates a unique file descriptor
  3. Returns the file descriptor
  4. Note: Document is not saved until you use the Save node

Requirements

  • When opening existing file: Valid file path to an existing .docx file
  • When opening existing file: Read permissions for the file
  • When creating new: No requirements

Error Handling

The node will return specific errors in the following cases:

  • File not found at the specified path
  • Invalid file path format
  • Insufficient permissions to read the file
  • Corrupted or invalid Word document
  • File is locked by another application

Usage Examples

Example 1: Open Existing Document

Scenario: Open an existing Word template to fill with data

// Set the path to the template
$local.templatePath = "/home/user/templates/invoice_template.docx";

Configuration:

  • File Path: {{$local.templatePath}}

Output:

  • Opens the template and returns a file descriptor in {{$message.word_fd}}
  • Use Replace Text or other nodes to modify the template

Example 2: Create New Document in Memory

Scenario: Create a new document without specifying a path initially

Configuration:

  • File Path: (leave empty)

Output:

  • Creates a blank document in memory with file descriptor in {{$message.word_fd}}
  • Add content with Add Text, Add Table, etc.
  • Save to a specific path using the Save node

Usage Notes

  • This is typically the first node in a Word automation flow
  • The file descriptor is essential for all subsequent Word operations
  • Opening a document doesn't lock it - other applications can still access it
  • Documents opened but not saved will lose any modifications
  • Always use the Save node to persist changes to existing documents
  • When creating a new document in memory, you must specify a path in the Save node

Tips for Effective Use

  1. Template Workflows: Use this node to open pre-formatted Word templates
  2. Variable Paths: Store file paths in variables for dynamic document processing
  3. Error Handling: Always check if files exist before attempting to open them
  4. Multiple Documents: You can open multiple documents in the same flow by storing different file descriptors
  5. Memory Documents: Use empty path for temporary documents that may not need saving

Best Practices

  • Verify File Existence: Use file system nodes to check if a file exists before opening
  • Handle Permissions: Ensure the robot has read permissions for the target file
  • Close Properly: Always save or explicitly handle documents at the end of your flow
  • Use Templates: Store frequently-used formats as templates and open them with this node
  • Path Format: Use absolute paths for reliability, or relative paths from the project directory

Common Errors and Solutions

ErrorCauseSolution
"File not found at [path]"File doesn't exist at the specified locationVerify the file path is correct and the file exists
"Failed to open Word document"Corrupted file or permission issuesCheck file integrity and permissions
"ErrNotFound"Invalid or empty path when trying to openProvide a valid file path or leave empty to create new
"ErrRuntime"Unexpected system errorCheck file isn't locked by another application

Difference from Create Word Node

FeatureOpen WordCreate Word
Can open existing filesYesNo
Can create in memoryYesNo
Immediately saves to diskNoYes
Requires file pathOptionalRequired
Overwrites existing filesNoYes (with option)

Use Open Word when you need flexibility, and Create Word when you want to immediately create a file on disk.