![]() |
|
#1
|
|||
|
|||
![]()
I'm trying to format a numeric merge field in Microsoft Word 365. I normally use a numeric picture switch like this:
\# 000000000000000000This is what the full field code looks like: { REF bookmark \# 000000000000000000 \* MERGEFORMAT }That's 18 total zeroes. I need to be able to have up to 18 digits showing with leading zeroes. If the referenced bookmark has 3 digits, I need 15 leading zeroes. If the bookmark has 15 digits, I need 3 leading zeroes. The length can be varied but always numbers. (There are no commas or dollar signs in the field.) When I use the switch mentioned above, the number is rounded off after 14 digits. If my number is 1234567890123456, the number that appears is 001234567890123500. If I don't include the numeric picture switch and just use the ref field, the numbers aren't rounded off but also the leading zeroes don't appear. If possible, I need the switch to remain so I can keep those leading zeroes. Any help will be greatly appreciated!! |
#2
|
||||
|
||||
![]()
You've posted this question as a mailmerge topic, but your field code refers to a REF field, not a mailmerge field.
Word cannot format numeric values having more than 15 significant digits. With some field math, though, you could use a field code to evaluate the number's order of magnitude and prefix the mergefield's unformatted output with the required number of 0s. Assuming you're using a mailmerge, if your source data contains the leading 0s (and is not just formatted to display leading 0s), a simple approach would be to create a dummy first record with some random text in that field. That way, the mailmerge will treat the data as text and output it with the leading 0s. Otherwise, you can use some field math in another field to determine the data field's order of magnitude and, from that, the number of leading 0s to output. For example, using an ASK field to demonstrate the process: Code:
{QUOTE↵ {ASK a "Input the raw number"}↵ {=a<10^17 \# "'0';;"}{=a<10^16 \# "'0';;"}{=a<10^15 \# "'0';;"}{=a<10^14 \# "'0';;"}{=a<10^13 \# "'0';;"}{=a<10^12 \# "'0';;"}{=a<10^11 \# "'0';;"}{=a<10^10 \# "'0';;"}{=a<10^9 \# "'0';;"}{=a<10^8 \# "'0';;"}{=a<10^7 \# "'0';;"}{=a<10^6 \# "'0';;"}{=a<10^5 \# "'0';;"}{=a<10^4 \# "'0';;"}{=a<10^3 \# "'0';;"}{=a<10^2 \# "'0';;"}{=a<10^1 \# "'0';;"}}{REF a} For a macro to convert the above field code representation into a working field code, see Convert Text Representations of Fields to Working Fields in the Mailmerge Tips and Tricks 'Sticky' thread at the top of this forum: https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Paul, a big sincere THANK YOU for your help! That did the trick and the number is appearing with leading zeroes, no matter the original amount of digits. Your assistance was clutch.
![]() |
![]() |
Tags |
field code, numeric picture switch |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Paste in picture, wrap with line, format paragraph before and picture...close to working | ctviggen | Word VBA | 3 | 03-25-2023 08:49 AM |
IF statement for numeric picture switch | jocotan88 | Mail Merge | 1 | 06-30-2021 06:40 PM |
![]() |
becca | Mail Merge | 2 | 06-08-2016 01:15 PM |
Format Switch \* Caps won't work in if..then statement | cwright | Word | 2 | 03-27-2014 04:19 PM |
![]() |
sbarron76 | Mail Merge | 3 | 05-03-2013 06:23 AM |