Syntax
SetDocumentVar VariableName$, VariableText$
SetDocumentVar(VariableName$, VariableText$)
Remarks
The SetDocumentVar statement associates the string VariableText$ with the active document. You use the VariableName$ argument with the function GetDocumentVar$() to return the associated string when the document is active. The variable is saved with the document. You can set multiple document variables for a single document. To delete a document variable, specify an empty string ("") for VariableText$. If the insertion point is not in a document — for example, if the macro-editing window is active — an error occurs.
The SetDocumentVar() function behaves the same as the statement, and also returns –1 if the variable is set successfully.
Example
This example prompts for a reminder note to store with a document before closing it. If the macro were named FileClose, it would run each time the user chose Close from the File menu (the instruction FileClose runs the built-in command).
The instruction On Error Goto CloseNow ensures that a WordBasic error doesn't appear if the user cancels the InputBox$() dialog box. The instructions Err = 0 and On Error Resume Next reset error handling and ensure that an error doesn't appear if the user cancels the prompt to save changes.
On Error Goto CloseNow worknote$ = InputBox$("Type a note for next time:") SetDocumentVar "reminder", worknote$ CloseNow: Err = 0 On Error Resume Next FileClose
For an example of an AutoOpen macro that displays the most recent reminder note each time the document is opened, see GetDocumentVar$().
See Also
GetDocumentVar$()