Reputation: 5027
I have some mail merge data from a data source which is sometimes used for display and sometimes used for calculation. How can I get Word to convert the value before a calculation?
For example, the field "Cash" comes from the datasource as 100.00CR (which in this case implies a negative value). I need to display the value as is in one place (with the CR), in another part of the mail merge I need to perform a calculation using this value. The problem is that Word thinks the value is a string because of the CR appended to the end of the value.
I was thinking I could write a Macro to convert the value prior to doing a calculation, eg,
{ =(ConvertToCalculationValue(110.00) *3)}
but this doesn't seem to work... Any ideas how I can do this without adjusting the data in the datasource?
Upvotes: 1
Views: 658
Reputation:
In the situation where you have a number followed by text, you should be able to do this:
{ SET X { MERGEFIELD theamount } }{ =X*3 }
where you write the name of your merge field instead of "theamount"
(As usual, all the {} have to be the special field code braces that you can insert using ctrl-F9 in Windows Word).
If you need to test whether or not "theamount" ends with "CR", you can use
{ IF "{ MERGEFIELD theamount }" = "*CR" "it ends with CR" "it doesn't end with CR" }
You may encounter problems if the text following the amount happens to be the currency symbol set up in your Regional Settings.
BTW, there is no (practical) way to invoke Word VBA macros/functions from within the "Field language". IN general it is best to try to ensure that your data source has your data in the format(s) that the merge needs, but...
Upvotes: 2