Link to home
Start Free TrialLog in
Avatar of Cheri Sheffield
Cheri SheffieldFlag for United States of America

asked on

VBA to display text based on a merge field value

In a mail merge document, I have a word "if" field that is setup as follows:
      Field name: EmployeeStatus  (this is a merge field)
      Comparison: Equal to
      Compare to: "N"
      Insert this text: "Non Exception"
      Otherwise insert this text: "Exception"

This works great except now I need to expand it so additional values for EmployeeStatus can be handled.  The next step (I am guessing) is to add a vba subroutine to contain a case statement something like:

Sub ConvertStatus()
      Select Case ActiveDocument.FormField.EmployeeStatus
               Case "N"
                     ActiveDocument.FormField.StatusText = "Non Exception"
               Case "E"
                        ActiveDocument.FormField.StatusText = "Exception"
               Case "X"
                        ActiveDocument.FormField.StatusText = "Exempt"
               Case "T"
                        ActiveDocument.FormField.StatusText = "Terminated"
               Case "R"
                     ActiveDocument.FormField.StatusText = "Retired"
      End Case
End Sub


Is this possible? or is the a better solution? I new to using vba with Word and need help. Any suggestions or comments would be greatly appreciated.

Thank you,
Cheri
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cheri Sheffield

ASKER

GrahamSkan:

Thank you so so much for your GREAT & quick answer.  You have really helped me out with this.
Thanks Cheri,

Your appreciation is most welcome

Graham