Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-08-2011, 08:00 AM
Daria11 Daria11 is offline Calculating dates Windows 7 64bit Calculating dates Office 2003
Novice
Calculating dates
 
Join Date: Jun 2011
Posts: 1
Daria11 is on a distinguished road
Default Calculating dates

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.
Reply With Quote
  #2  
Old 06-08-2011, 06:54 PM
macropod's Avatar
macropod macropod is offline Calculating dates Windows 7 32bit Calculating dates Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,224
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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
You may need to change the date output formats to suit your needs.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
calculating, dates, macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
calculating points and division in excel edward masoya Excel 1 05-09-2011 06:31 AM
Calculating dates Calculating age at date jamierbooth Excel 2 02-22-2011 03:35 AM
Calculating dates Calculated dates. 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft