View Single Post
 
Old 08-11-2014, 05:00 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Whether the macro results will be shown in real time rather depends on the macro code and what it is supposed to do. For example, add a DocVariable field to the document

{ DOCVARIABLE "varText" }

Create a macro

Sub Test1()
Dim oFld As Field
ActiveDocument.Variables("varText").Value = "This is text"
For Each oFld In ActiveDocument.Fields
If oFld.Type = wdFieldDocVariable Then
If InStr(1, oFld.Code.Text, "varText") > 0 Then oFld.Update
Exit For
End If
Next oFld
End Sub

and run that from a button on the userform


Private Sub CommandButton2_Click()
Call Test1
End Sub

The docvariable field will be updated in real time.

Similarly you can add the content of a text box to a docvariable and associated field

Private Sub TextBox1_Change()
Dim oFld As Field
ActiveDocument.Variables("varTextBox1").Value = TextBox1.Text
For Each oFld In ActiveDocument.Fields
If oFld.Type = wdFieldDocVariable Then
If InStr(1, oFld.Code.Text, "varTextBox1") > 0 Then oFld.Update
Exit For
End If
Next oFld
End Sub

Graham Mayor - MS-MVP (Word)
www.gmayor.com
Reply With Quote