#1
|
|||
|
|||
Loop Macro to Edit Date
I have a file containing multiple word documents. Each will contain the text "Month Year" (ex January 2014). I'd like the macro to open each file in folder and change the date to the previous month (compared to current) with proper year (i.e. December 2013 will become January 2014). As such the macro, if ran in 10 days, would change whatever month year combination to "February 2014".
Any help in this would be greatly appreciated. Thanks in advance -J |
#2
|
||||
|
||||
If you want the documents to always update to whatever the preceding month is, it would be better to replace the dates with a field code that does the updating, rather than relying on macros.
To see how to do this and just about everything else you might want to do with dates in Word, check out my Microsoft Word Date Calculation Tutorial, in the 'Sticky' thread at the top of the Word forum: https://www.msofficeforums.com/word/...-tutorial.html In particular, look at the item titled 'Calculate a month and year, using n months delay'. Do read the document's introductory material. PS: I seem to recall providing you with a macro to change the dates as per your current request, in this thread: https://www.msofficeforums.com/word-...edit-date.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Cross-posted at: http://social.msdn.microsoft.com/For...?forum=worddev
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Sorry for the cross post will properly site next time.
I thought your name looked familiar. Thanks again for the previous help. The problem I have now is that similar setup (i.e. boat load of documents in a single folder), but now the date format is MMMM YYYY not MMMM DD, YYYY. Could you possible explain to me (while you doing it would fix my problem, offer no chance for learning) which variables are needing to be edited in the previous macro to yield the desired outcome. Respectfully Grateful, -J |
#5
|
||||
|
||||
So, do the dates you're looking for this time include the day of the month, or only the month name & year? And what do you want the output expression to show? I recall we had a similar discussion last time ... If you're only processing month & year dates and there are also other dates in the document that have the day as well, what do you want to do about those?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
The document contains month and year (December 2013) and the out put should be in the same format. There is only one occurrence per page of a date and it will be in the same format and without a separating comma.
|
#7
|
||||
|
||||
In that case, only a few minor changes to the previous code are required, being nothing more that deleting the day parts of the date references:
Code:
... StrRep = Format(DateAdd("d", -1, CDate(Month(Now()) & "/1/" & Year(Now()))), "MMMM YYYY") ... .Text = "[ADJMO][abceghlmnorstuy]{2,7} [12][0-9]{3}" .Execute Replace:=wdReplaceAll .Text = "February [12][0-9]{3}" .Execute Replace:=wdReplaceAll .Text = "[AJSN][beilmnoprtuv]{4,8} [12][0-9]{3}" ... Code:
.Text = "[ADJMO][abceghlmnorstuy]{2,7} [12][0-9]{3}" .Execute Replace:=wdReplaceAll .Text = "February [12][0-9]{3}" .Execute Replace:=wdReplaceAll .Text = "[AJSN][beilmnoprtuv]{4,8} [12][0-9]{3}" Code:
.Text = "<[JFMASOND][a-ceg-il-pr-vy]{2,8} [12][0-9]{3}>"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Thanks so much for the help and the break down. I tend to be pretty handy with excel macros, but not so much with word macros.
Thanks again, -J |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Loop Macro to Edit Date | damaniam | Word VBA | 11 | 12-05-2013 08:28 AM |
Macro to loop in Word | Yamaha Rider | Word VBA | 2 | 02-07-2012 05:33 PM |
WORD Macro - import picture - resize - position - page break - loop | Nano07 | Word VBA | 2 | 11-02-2011 05:14 AM |
Macro to loop in subfolders, change links, export xml data | Catalin.B | Excel Programming | 2 | 09-08-2011 11:37 PM |
'Last edit date' | markg2 | Word | 3 | 12-26-2010 04:27 PM |