Results 1 to 2 of 2
2013-03-28, 03:41 #1
- Join Date
- Jan 2001
- Melbourne, Australia
- Thanked 2 Times in 2 Posts
Convert filename to date text in document - Fields plus VBA?
For a very long time I've been building a weekly task grid using a complex set of SEQ and REF fields to create date headings for the table. Unfortunately I have to set the starting day and month manually for each document. Yet each document has the starting date embedded in its filename.
So, what I would like to do is extract the starting date from the filename, turn it into a date that I can increment, and display the sequence of seven dates. The extraction needs to be done whenever the filename changes, since I usually just Save As the previous week's file to begin.
I've discovered all sorts of fun problems with this:
- Word has no text manipulation fields
- Word has no date manipulation fields
- Word VBA can only be saved in docm and dotm files
- Word VBA doesn't seem to have an OnSave event
Before I spend any more time on this, I'm wondering what my best option is to proceed.
1. Save my time and keep manually editing the SEQ fields.
2. Use a FILLIN field to update the SEQ fields from a dialog box. (Will I have to reenter every time I open the document?)
3. Get Word to treat part of the filename (eg: "Info20130105.docx") as a number. How?
4. Create a macro in the template to pop up a dialog whenever I create a new doc or Save As to prompt me for the starting date to set the initial SEQ fields or a BOOKMARK. How do I access these events? Is SEQ or BOOKMARK better?
5. Same as 4, but use the filename, not a dialog.
6. Same as 4 or 5 but skip fields altogether and let the macro do all the work.
Thanks heaps. This has been bugging me for years.
2013-03-28, 07:06 #2
- Join Date
- Jan 2001
- Melbourne, Victoria, Australia
- Thanked 249 Times in 231 Posts
Use a Date Content Control rather than a field. You have plenty of ways to format and can manipulate the controls easily using VBA.
Store the macro in an attached template, not in each document you create. This gives you a single document to maintain code in.
Word does have an OnSave event - either hijack the FileSaveAs command or use the DocumentBeforeSave event.
Post a sample doc so we can see what you are actually working with and we can suggest easier ways of doing what you need.Andrew Lockton, Chrysalis Design, Melbourne Australia