Can I use a Macro within a Word Formula? How?

A

Adam Eichen

Currently, I use a formula to interpret a bookmark used in a form to display
a converstion. The formula is currently one of two options, so I use an if
statement. I would like to change it to one of 20 options. I would like to
use a Macro and pass thh bookmarked value to the Macro and have the Macro
return the value. Is this possible? how?
 
G

Greg

Yes this could be done using Select Case in the macro. You will have
to be more specific on where the bookmark is located (e.g., is it the
value of a form field itself) and how you want to fire the macro.

You can fire the macro on entry or exit of a form field.

Let's assume that the bookmark in the value of a formfield bookmarked
"Input" you coud set a macro to run on exit that could set the value
of another formfield (let's bookmark it "Output") or to define a
document varialble "Output"

Sub Test()
Dim oTest As String
oTest = ActiveDocument.FormFields("Input").Result
Select Case oTest
Case Is = "A"
ActiveDocument.FormFields("Output").Result = "Airplane starts with
an A."
'or
ActiveDocument.Variables("Output").Value = "Airplane starts with an
A."
Case Is = "B"
ActiveDocument.FormFields("Output").Result = "Boy starts with a B."
'or
ActiveDocument.Variables("Output").Value = "Boy starts with a B."
Case Else
'Do Nothing
End Select
'If using the Varible include the following line.
ActiveDocument.Fields.Update
End Sub

If you use the Variable then just include a DocVariable field in the
document.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top