Using environmental variables
Who is this article for?
Users looking to pull information from system fields into documents or emails.
No special access or permissions are required.
To dynamically update documents, emails, and workflows when an item is opened or crated, you can use system-specific fields, also known as environment variables. These fields may include revision information, publication dates, expiration details, and many other types of data.
This article walks you through how you can use these in your documentation.
1. Understanding variables
For documents, environment variables update through the document automation process. Updates are triggered upon publication, check-in, release for approval/review, or manually through the Run Document Automation command. Automation may also be configured as a Scheduled Task.
For Office files, these fields may also be referred to as embedded variables or field codes, and can reside in the header/footer or document body of the file itself.
For HTML files, environment variables can only reside in the header/footer defined in the folder properties, not the body. The same fields are available for all file types, however.
2. Setting up files
Before you can use variables in Excel files, you need to make your file macro-enabled.
To macro-enable your file:
- Check the document out for editing.
- Open the file.
- Switch to the View tab.
- Click Macros.
- Select View Macros.
- Enter AutoOpen as a Macro name.
- Change the Macros in dropdown to the name of the file you're adding the macro to.
- Click Create.
- Copy the following and paste it into the Visual Basic page.
If there's already content in the page, overwrite it.
Public Function DocProperty(property As String) As String
Dim WB As Workbook
On Error Resume Next
If TypeOf Application.Caller Is Range Then
Set WB = Application.Caller.Parent.Parent
Else
Set WB = ActiveWorkbook
End If
DocProperty = WB.CustomDocumentProperties(property)
WB.Saved = True
End Function
Public Sub Auto_Open()
' - This macro will refresh any cells where the formula
' - is a call to the DocProperty function
'
Dim ws As Worksheet
Dim cell As Range
For Each ws In ThisWorkbook.Worksheets
HeaderFooter ws
For Each cell In ws.UsedRange.Cells
If InStr(cell.Formula, "DocProperty") 0 Then
cell.Formula = cell.Formula
End If
Next cell
Next ws
End Sub
Private Sub HeaderFooter(wks As Worksheet)
Dim sValue As String
Dim sFooter As String
wks.PageSetup.LeftHeader = "&L&B&I" & "Qualtrax"
wks.PageSetup.RightHeader = "&R" & DocProperty("##ID##") & Space(2) & DocProperty("##TITLE##") & Chr(13) _
& "&R" & "Original SOP Number - " & DocProperty("##ORIGINAL_SOP_NUMBER##")
wks.PageSetup.LeftFooter = "&L" & "Status: " & DocProperty("##STATUS##") & Chr(13) _
& "Issue Date: " & Format(DocProperty("##DATE_PUBLISHED##"), "MM/dd/yyyy") & Space(2) & "Revision: " & DocProperty("##REVISION##")
End Sub
- Save the Visual Basic page.
The macro is now saved to the document and will be present for any user who views or edits it in the future, as long as their macro security permits.
Setting up macro security
Environment variables in your Excel files should be configured to update automatically each time the document is opened. To do this, you'll need to install the AutoOpen macro.
Because macros from untrusted sources can be used to deliver malicious code, Microsoft provides security settings that prevent macros from running automatically.
To set up macro security:
- Open Excel.
- Click File.
- Select Options.
- Navigate to the Trust Center.
- Choose Macro Settings from the list on the left.
- Select one of the settings depending on the security you want to maintain.
- Click OK.
If you chose Disable all macros without notifications, you will need to add your working folder as a trusted location.
To add a trusted location:
- In the Trust Centre, go to Trusted Locations.
- Tick Allow Trusted locations on my network.
- Click Add new location...
- Select your working folder location.
- Click OK.
3. Using variables
3.1. Excel files
Environment variables from the variables list are available to add to your Excel documents once you set up your file to be macro-enabled (i.e. .xls or .xlsm).
You can add them to the Header/Footer or the body of your spreadsheet without any additional set up.
Our PDF viewer does not support the execution of macros during the conversion of documents to PDF format. Consequently, any environment variables applied to Excel files will only be accurate when viewed in their original format.
3.2. Word files
Environment variables from the variables list are available to add to your Word documents as soon as they're created or checked into the system. Once the document has hit the system, all available variables can be added directly from Word.
To add a variable to Word files:
- Check the document out for editing.
- Open the file.
- Switch to the Insert tab.
- Click Quick Parts.
- Select Field....
- Select DocProperty from the Field names.
- Choose the environment variable from the Property list.
- Click OK.
You will see the field is now included in your document. Repeat the steps for each field you want to add.
Need to modify the date format?
You can customise the date formatting by manipulating the advanced properties of the field.
3.3. HTML files
Environment variables only work for HTML files when added to the Header/Footer tab of the Folder Properties the document resides in.
To add a variable to HTML files:
- Determine which fields you want to add from the list of variables.
- Add them to the Header/Footer tab as they appear in the list.
- Save your file.
4. List of variables
4.1. Document variables
Environment variables for document-related data can be used in any document.
You can toggle between the normal reading view and one showing the locations of inserted variables by pressing ALT + F9 on your keyboard. This can clarify where variables are, if they're present at all, when it's not readily clear.
All fields must be added with the "##" symbols, in all uppercase letters, and with any "_" characters. When updated, system data overwrites these variables with system information.
Approve
| Variable | Description |
| ##APPROVAL_RECORD## | Date, time, and user of each approval for the current revision. Any incomplete approvals are recorded as "Still Pending." The date, time, and username of any canceled release is also included. In Word documents, when the approval record contains more than 255 characters, it can be split into multiple variables (##APPROVAL_RECORD1##, ##APPROVAL_RECORD2##) to prevent the list from being cut short. To do this, insert these variables in numerical order on the same line, with no spaces. |
| ##APPROVAL_RECORD_MULTILINE## | Approval record, formatted to display on separate lines rather than separated by commas. This variable works only for Word documents. When the approval record contains more than 255 characters, it can be split into multiple variables to prevent the list from being cut short (with the first set as ##APPROVAL_RECORD_MULTILINE1##, ##APPROVAL_RECORD_MULTILINE2##). To do this, insert these variables with no spaces in numerical order on the same line. |
| ##APPROVED_BY## | User who most recently approved the current revision. |
| ##APPROVERS## |
List of all Approvers as defined in the Doc List. This variable displays the complete list of document approvers, even when the document is in edit and also when it is in the process of being approved. |
| ##DATE_APPROVED## | Date and time the most recent approval was completed. |
| ##DATE_REJECTED## | Date and time the current revision was rejected by an approver. |
| ##DATE_RELEASED## | Date and time the current revision was released for approval. |
| ##REJECTED_BY## | User who most recently rejected the current version. |
| ##REJECTION_REASON## | Comments entered by the last user to reject the document during a release for approval. |
| ##REVISION_NOTE## | Comments entered in the Changes Made field when the current revision was released for approval or review. |
Publish
| Variable | Description |
| ##DATE_FIRST_PUBLISHED## | Date and time the first revision of the document was published. |
| ##DATE_PUBLISHED## | Date and time the current revision of the document was published. |
Review
| Variable | Description |
| ##DATE_RELEASED_FOR_REVIEW## | Date and time the current revision was released for review. |
| ##DATE_REVIEWED## | Date and time a review was performed for the current revision. If no revision has been performed, this variable is not populated. If any review is performed, the date/time of the last person's review is listed, regardless of whether all reviews are completed or the release for review is canceled. |
| ##REVIEW_RECORD## | Date, time, and user of each review for the current revision. Any incomplete reviews are listed as 'Still Pending'. If the release for review was canceled, the date, time and user are recorded for the cancellation as well. |
| ##REVIEWED_BY## | User who most recently reviewed the current revision. |
| ##REVIEWED_COMMENTS## | Last comment entered by a reviewer for the current revision. |
| ##REVIEWERS## | List of reviewers defined in the Doc List. |
| ##REVISION_NOTE## | Comments entered in the changes made field when the current revision was released for approval or review. |
Edit
| Variable | Description |
| ##DATE_EXPIRED## | Date the document last expired to 'Edit' status. If published, the date and time the document expires next. |
| ##DATE_STARTED## | Date and time the current revision began, whether or not that revision has been published. |
| ##EDIT_REASON## | Comments entered by the editor or the user making an edit request when the document was placed in 'Edit'. |
| ##EDITOR## | Editor for the current revision. |
Retire
| Variable | Description |
| ##DATE RETIRED## | Date and time the document was retired. |
| ##RETIRED_BY## | User who retired the document. |
| ##RETIREMENT_REASON## | Comments entered by user retiring the document. |
Properties
| Variable | Description |
| ##DOCUMENT_MANAGER## | User specified as the Document Manager. |
| ##EXTENSION## | View type of the document. |
| ##EXTENSION_DESC## | Short description of the view type. |
| ##ID## | Unique ID number of the document. |
| ##REVISION## | Number of revisions, including the current unpublished revision. |
| ##STANDARDS## | List of all standards associated with the document. |
| ##STATUS## | Processing status of the document. |
| ##TITLE## | Title of the document. |
| ##CUSTOM_FIELD_NAME## | If any Custom fields are specified in the document's document properties - Custom fields tab, the values from those fields can be displayed by using the field name. For instance, if you wanted to display the value from a Custom field called "Manual revision Number", you'd use the following format: ##MANUAL_REVISION_NUMBER##. |
Dependencies
| Variable | Description |
| ##DEPENDENCIES## | List of all Dependencies associated with the document, shown in (ID) Title format. |
4.2. Workflow variables
Environment variables for workflow-related data can only be added to email actions and reminders.
They cannot be inserted directly into workflow instances for users to view when processing since most of this information is already displayed in the processing details at the top of the instance or in the body itself.
All fields must be added with the "##" symbols, in all uppercase letters, and with any "_" characters. When updated, system data overwrites these variables with system information.
| Variable | Description |
| ##CUSTOM_FIELD_NAME## | If any Custom fields are specified in the document's document properties - Custom fields tab, the values from those fields can be displayed by using the field name. For instance, if you wanted to display the value from a Custom field called "Manual revision Number", you'd use the following format: ##MANUAL_REVISION_NUMBER##. |
| ##DATE_STARTED## | Date the workflow instance was initiated. |
| ##ID## | Unique ID number of the workflow instance. |
| ##INSTANCE_DISPLAY_FIELD## | Value entered in the workflow instance for the field chosen as the Inbox Display field on the workflow definition. This value along with the instance ID# appear in the user's Inbox to help distinguish one workflow item from another, and may be similarly useful in email notifications. |
| ##STATUS## | Step the workflow instance is currently in. |
| ##LAST_ACTION_BY## | Date and time of the workflow instance's last Route. |
| ##TITLE## | Name of the workflow as specified in the workflow definition. |
| ##WORKFLOW_INITIATOR## | User who began the workflow instance. |
| ##WORKFLOW_DELETED_BY## | User who deleted the workflow instance through the workflow definitions Administration page. |
| ##WORKFLOW_DATE_DELETED## | Date the workflow instance was deleted through the workflow definitions Administration page. |
| ##WORKFLOW_RESPONSIBLE_PARTIES## | When used in email actions, the names of all users designated as Responsible Parties for processing the action are listed. When used in email reminders, the names of all users designated as Responsible Parties for processing the current step of the workflow instance are listed. |
| ##WORKFLOW_COLLABORATORS## | When used in email actions, the names of all users designated as Collaborators for processing the action are listed. When used in email reminders, the names of all users designated as Collaborators for processing the current step of the workflow instance are listed. |