Cheri Sheffield
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.E mployeeSta tus
Case "N"
ActiveDocument.FormField.S tatusText = "Non Exception"
Case "E"
ActiveDocument.FormField.S tatusText = "Exception"
Case "X"
ActiveDocument.FormField.S tatusText = "Exempt"
Case "T"
ActiveDocument.FormField.S tatusText = "Terminated"
Case "R"
ActiveDocument.FormField.S tatusText = "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
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.E
Case "N"
ActiveDocument.FormField.S
Case "E"
ActiveDocument.FormField.S
Case "X"
ActiveDocument.FormField.S
Case "T"
ActiveDocument.FormField.S
Case "R"
ActiveDocument.FormField.S
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks Cheri,
Your appreciation is most welcome
Graham
Your appreciation is most welcome
Graham
ASKER
Thank you so so much for your GREAT & quick answer. You have really helped me out with this.