![]() |
#1
|
|||
|
|||
![]()
I need a Word macro which will look through the current document and find/replace all instances of certain words as follows:
"+today" is replaced by today's date "+1 week" is replaced with the date one week hence "+2 weeks" is replaced with the date two weeks hence I don't want them updated each time the document is opened. I have spent ages looking online for a solution but everyone says that any macro involving calculating dates is very difficult. I don't understand why this should be the case. I want to be able to copy and paste the macro so I can use it. |
#2
|
||||
|
||||
![]()
Hi Daria11,
Yes calculating dates is complex if you need to do it with field coding. To see how to do just about everything you might want to do with date calculations in Word, check out my Microsoft Word Date Calculation Tutorial, at: http://lounge.windowssecrets.com/ind...owtopic=249902 or http://www.gmayor.com/downloads.htm#Third_party Do read the document's introductory material. However, for what you've descibed, date calculation isn't much of an issue. Try the following macro: Code:
Sub DateUpdater() Application.ScreenUpdating = False Dim FRDoc As Document, FRList As String, j As Long With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .MatchWholeWord = True .MatchCase = True .Text = "+Today" .Replacement.Text = Format(Date, "dddd, d MMMM, YYYY") .Execute Replace:=wdReplaceAll .Text = "+1week" .Replacement.Text = Format(DateAdd("d", 7, Date), "dddd, d MMMM, YYYY") .Execute Replace:=wdReplaceAll .Text = "+2weeks" .Replacement.Text = Format(DateAdd("d", 14, Date), "dddd, d MMMM, YYYY") .Execute Replace:=wdReplaceAll End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
Tags |
calculating, dates, macro |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
calculating points and division in excel | edward masoya | Excel | 1 | 05-09-2011 06:31 AM |
![]() |
jamierbooth | Excel | 2 | 02-22-2011 03:35 AM |
![]() |
Ziggy-R | Word | 10 | 09-28-2010 01:42 AM |
Calculating Form Fields in Microsoft Word | wubba80 | Word | 1 | 06-25-2010 12:42 AM |
Adding dates | mkkram | Word | 0 | 11-27-2006 09:18 AM |