
When updated, the field returns the value assigned to the MyVar document variable. You can, however, insert the contents of a document variable directly within a document by using the DOCVARIABLE field, as follows: Typically, users would never see the contents of a document variable they are intended primarily for use within macros. Heres the new code:Sub myconverttoPROCESSstepsaddBLOCKsnew(). I had already worked on a similar one before. I prompt the user to enter a value for.1 answer Top answer: I was able to answer my own question. This string is XXXX which is found more than once. For instance, the following macro line will create a variable called MyVar and assign it a value of 27:Ī Name:="MyVar", Value:=27Īt a later time, you can access the value associated with the variable by using the variable's name, as follows:ĭefaultToUse = ActiveDocument.Variables("MyVar") The macro replaces a string found in a selection.

All you need to do is provide the name for the variable and the value you want assigned to the variable. To create a document variable within a macro, you use the Add method with the Variables collection. Next, adjust your completed TEXT function to include the ASCII function CHAR (10) where you want the line break. These defaults can be stored within document variables. First, select the cell or cells where you want this to happen and use Ctrl+1 to bring up the Format > Cells dialog, then Alignment > Text control > check the Wrap Text option.

For instance, you may want your macro to remember the defaults that it uses when prompting the user. Document variables are typically used to maintain some sort of information from one invocation of a macro to the next.

Visual Basic for Applications allows you to create persistent variables that are associated with a document.
