You can use the SmartDocs API to manage the reusable variables in a Microsoft® Word document to:
- Create a new variable in a document.
- Update the name, value, and properties of an existing variable.
- Insert a variable into your document content.
- Get all of the variables currently in a document.
- Determine if a document contains any variables.
- Determine if a document contains a variable with a specific name.
This code sample demonstrates how to use the SmartDocs API to create a new variable in a document. The variable is named Product_Name and it is assigned the value SmartDocs Professional Edition. If the variable is successfully created, the name of the variable is displayed in a message box.
Below are code samples that show how you can use the SmartDocs API to manage reusable variables. The code samples are written in VBA, but these same functions can be performed in any COM-supported programming language.
NOTE: The code samples below assume you have already retrieved a reference to the SmartDocsAutomationDocument object and have stored the reference in a VBA parameter named AutomationDocument.
Create New Variable
Dim automationResult As SmartDocsAutomationResult Set automationResult = automationDocument.CreateReusableVariable ("Product_Name","SmartDocs Professional Edition", False) If automationResult.Success Dim reusableVariable As SmartDocsReusableVariable Set reusableVariable = automationResult.Object MsgBox reusableVariable.Name Else MsgBox "Error" End If
Can you provide a code sample that lists all of the variables currently used in a document (i.e. not the variable list shown in the Task Pane)?