Search code examples
vbavisual-studioms-wordmergefield

MERGEFIELD for Values with Superscript for dates Microsoft Word


Having 1{sup|er} janvier 2012 for the MergeField Microsoft Word for Email.

The format that we have is fmDD"{sup|er}" month YYYY

This is the format that we currently use and wondering if there is a way for this to be corrected in the Word file

{MERGEFIELD theDate} We use this on the Microsoft Word file but it didn't work. The result is at it is 1{sup|er} janvier 2012.

The Expected behavior is 1er janvier 2012 for the Microsft Word.

Thanks in advance.


Solution

  • This takes a complex field with text already formatted as superscript in the field.

    From my page on Date Fields in Microsoft Word is the following field structure.

    {QUOTE{CREATEDATE @ "dddd 'the' d"}{IF{=(MOD({={CREATEDATE @ d}+89},100)>2)*(MOD({={CREATEDATE @ d}+9},10)<3)}= 1 {=MOD({CREATEDATE @ d},10)-2 # rd;st;nd} th}{CREATEDATE @ "' of' MMMM, yyyy"}}

    Here is a screenshot of the field which shows the superscripting:

    screenshot of field code

    This field is from my Legal Toolbars Add-In as a superscripted CreateDate. It is an AutoText entry there. Here is a screenshot from the Add-In menu.

    screenshot from Add-In

    You could try to modify it to use your mergefield instead of CREATEDATE.

    {QUOTE{MERGEFIELD theDate \@ "dddd 'the' d"}{IF{=(MOD({={MERGEFIELD theDate \@ d}+89},100)>2)*(MOD({={MERGEFIELD theDate \@ d}+9},10)<3)}= 1 {=MOD({v \@ d},10)-2 \# rd;st;nd} th}{MERGEFIELD theDate \@ "' of' MMMM, yyyy"}}
    

    (I have not tried this with a merge field. You would need to superscript parts as shown in the screenshot.)

    This was based on Paul Edstein (macropod)'s work, in particular, his Date Calculation Tutorial. If you want to understand this, I recommend downloading that tutorial and going through it. If you do, pay attention especially to the introductory part. It has multiple date calculation fields which are very complex.

    Refer to my page on date fields for more. You cannot simply type the braces. Word must insert them. See also: my article on Dealing with Fields in Word.