How do I compute the length of the longest text for a date in Word ?
A Word document to compute the length of the longest text for a date in Word.
Working on the layout of a Microsoft Word French and English versions of a document template with a customer, we were trying to determine where to position a tab, so that we had the document date appear on the right of the page, near the right border. We put a tab and wrote the date, Monday 18 January 2016, as an example, to have some visual feedback. “Do you think that our tab position is far enough on the left, so that our date text will not horribly wrap on the next line ?” (that’s me translating the customer’s question). Good point !
In our template, the date of the day is expressed in the format <day name> <day number> <month name> <year>, meaning we have: Tuesday 19 January 2016 for the 1.19.2015.
We’re dealing with proportional fonts (an “i” takes less space than a “c” to print), so how can we know the maximum space to reserve for our date text, or at what distance from the right border of the page should we position our tab to avoid letting the date text wrap ?
Illustration – Where should I put the tab ?
Solution for French and English
To determine the space we have to preserve for the text of the date, we’re simply going to compute the length in centimeters (Europe here guys!) of the date texts for all the dates of the current year (we could have gone further on 10 years but that would be an overkill here). We then keep the length of the last of the longest texts.
To compute this length, for date texts in English or French, you can download this Word document (this is a zip archive, you can extract it with 7zip). Double click it and follow the instructions on the page.
Free download and unlimited use. Download this template from devinfo.net: word_longest_day.zip
Note on our Word documents containing macros
This Word document templates contains macros. Which means that it comes bundled with executable code. Such downloadable documents that we post on devinfo.net are numerically signed with our code certificate. This ensures that you got a valid copy that has not been tampered with malicious code. When you open the document for the first time, you’ll see the Word standard dialog for numerically signed documents, where you’ll be able to trust our publisher certificate.
To compute other text lengths
Need to have the same feature for any other text ? – Drop me a comment to see what I can do for the next update.
How is it done ?
I’ll post source code along with my comments in a future post.
But I’ll need you to motivate me, so drop me an inspiring comment to speed up the next post, thanks 😉 !