Close Word
Closes an open Word document and optionally saves changes. This node can also export the document to different formats (PDF, Text, Doc, Docx) before closing.
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.
If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
- File Descriptor - File descriptor ID from the Open Word node. Default variable is
word_fd.
Options
-
Save Changes - Whether to save changes before closing the document. Default is
false.true- Saves the document with all changesfalse- Closes without saving (discards changes)
-
Save As - Optional format to save the document. Available options:
_(default) - No format conversionPdf- Save as PDF formatText- Save as plain text (.txt)Doc- Save as Word 97-2003 format (.doc)Docx- Save as modern Word format (.docx)
-
Save As Path - Full path where the document will be saved in the selected format. Required when Save As format is selected.
Use Cases
- Closing documents after completing automated updates
- Saving documents after adding content
- Exporting Word documents to PDF format
- Converting Word documents to text files
- Batch processing and closing multiple documents
- Creating backups in different formats
- Properly releasing Word application resources
Example: Simple Close with Save
Closing a document and saving changes:
- Use Open Word to open the document
- Perform operations (Add Text, Replace Text, etc.)
- Add the Close Word node
- Set Save Changes to
true - Leave Save As as default (
_)
Example: Export to PDF
Converting a Word document to PDF:
- Use Open Word:
C:\Documents\Report.docx - Perform any necessary updates
- Add the Close Word node
- Configure options:
- Save Changes:
true - Save As:
Pdf - Save As Path:
C:\Documents\Report.pdf
- Save Changes:
// Workflow: Word to PDF conversion
// Open Word: C:\Documents\Invoice.docx
// Replace Text: Fill in customer data
// Close Word:
// - Save Changes: true
// - Save As: Pdf
// - Save As Path: C:\Documents\Invoices\Invoice_2024_001.pdf
Example: Multiple Format Export
// Export the same document to multiple formats
// Step 1: Create and populate document
// Open Word: C:\Temp\Report.docx
// Add content...
// Step 2: Save original
// Close Word: Save Changes = true
// Step 3: Reopen and export to PDF
// Open Word: C:\Temp\Report.docx
// Close Word:
// - Save Changes: false
// - Save As: Pdf
// - Save As Path: C:\Reports\Report.pdf
// Step 4: Reopen and export to Text
// Open Word: C:\Temp\Report.docx
// Close Word:
// - Save Changes: false
// - Save As: Text
// - Save As Path: C:\Reports\Report.txt
Format Comparison
| Format | Extension | Use Case | Notes |
|---|---|---|---|
| Docx | .docx | Modern Word format | Full formatting, modern standard |
| Doc | .doc | Legacy Word format | Compatibility with older Word versions |
| Distribution, printing | Read-only, preserves layout | ||
| Text | .txt | Plain text extraction | No formatting, text only |
PDF Export Benefits
- Preserves formatting - Layout remains consistent
- Universal compatibility - Can be opened on any device
- Read-only - Prevents unauthorized editing
- Smaller file size - Often more compact than Word files
- Professional - Standard for sharing documents
Text Export Use Cases
- Extracting content for analysis
- Creating searchable archives
- Data migration
- Content indexing
- Simple text backups
Always set Save Changes to true if you want to keep modifications made during the automation. If you only want to export without modifying the original, use Save As with a different path.
Common Workflows
Workflow 1: Edit and Save
// Open document
// Make changes (Replace Text, Add Table, etc.)
// Close Word: Save Changes = true
Workflow 2: Create PDF from Template
// Open template: Invoice_Template.docx
// Replace placeholders with customer data
// Close Word:
// - Save Changes: false (don't modify template)
// - Save As: Pdf
// - Save As Path: C:\Invoices\Customer_Invoice.pdf
Workflow 3: Batch Convert to PDF
// For each Word file in folder:
// Open Word: filepath
// Close Word:
// - Save Changes: false
// - Save As: Pdf
// - Save As Path: pdfPath
Common Errors
- "Invalid File Descriptor" - The file descriptor is invalid or the document was already closed. Ensure Open Word was executed first.
- "Save As format must be selected when Save As Path is provided" - If you provide a path, you must select a format (Pdf, Text, Doc, or Docx).
- "Save As Path cannot be empty when Save As format is selected" - You must provide a valid file path when using the Save As option.
- Access denied - Ensure the robot has write permissions to the target directory.
- File already exists - The target file may be open or locked by another process.
Notes
- Closing the document releases all resources and removes the file descriptor.
- The Word application instance is terminated when the document is closed.
- You cannot use the same file descriptor after closing the document.
- If Save Changes is
falseand no Save As is specified, all changes are lost. - The Save As operation creates a new file; the original remains unchanged unless Save Changes is also true.
- Multiple documents can be open simultaneously with different file descriptors.
Best Practices
- Always pair Open Word with Close Word to prevent resource leaks.
- Set Save Changes to
trueif you made modifications you want to keep. - Use descriptive file names when exporting to different formats.
- Create output directories before saving files to them.
- Handle errors gracefully - use Try/Catch to ensure documents are closed even if errors occur.
- When converting to PDF, verify the output path has a
.pdfextension. - Consider using timestamp in filenames for batch operations:
Report_2024_12_23.pdf
Resource Management
// Good practice: Always close documents
try {
// Open Word
// Perform operations
// Close Word
} catch (error) {
// Ensure Close Word is called even on error
// Close Word: Save Changes = false
}
File Naming Tips
// Timestamped output
// Save As Path: C:\Reports\Report_${timestamp}.pdf
// Customer-specific output
// Save As Path: C:\Invoices\${customerName}_Invoice.pdf
// Sequential numbering
// Save As Path: C:\Documents\Doc_${sequenceNumber}.docx
See Also
- Open Word - Open documents for editing
- Create Word - Create new documents
- Add Text - Add content before closing
- Replace Text - Update content before closing