You can use the SmartDocs Application Programming Interface (API) to update reusable variables from your own custom VBA code.
The following VBA code sample shows how you can use the SmartDocs API to update a reusable variable called Product_Name to the value SmartDocs. Simply drop this macro into your own VBA code, ensure your document has a variable called Product_Name, and run this macro to see the variable value update.
Sub SmartDocsUpdateReusableVariableExample() ' ////////////////////////////////////////// ' // Get the SmartDocs automation object. //
' ////////////////////////////////////////// Dim AutomationService As Object
Set AutomationService = Application.COMAddIns("ThirtySix.SmartDocs.AddIn").Object.Automation If Not AutomationService.Initialized Then AutomationService.Initialize End If ' /////////////////////////////////// ' // Get the document to automate. // ' /////////////////////////////////// Dim AutomationResult As Object Set AutomationResult = AutomationService.GetDocument(ActiveDocument) If Not AutomationResult.Success Then MsgBox "Error occurred getting document to automate: " & AutomationResult.Message Exit Sub End If Dim AutomationDocument As Object Set AutomationDocument = AutomationResult.Object ' //////////////////////////////////////////////////////// ' // Update Product_Name variable value to "SmartDocs". // ' //////////////////////////////////////////////////////// Dim ReusableVariable As Object
Set AutomationResult = AutomationDocument.UpdateReusableVariable("Product_Name", "Value", "SmartDocs") If Not AutomationResult.Success Then MsgBox "Error occurred updating reusable variable: " & AutomationResult.Message End If Set ReusableVariable = AutomationResult.Object MsgBox "Reusable variable successfully updated: " & ReusableVariable.Value End Sub
Comments