Macro use

S

Sarah at DaVita

I am new at using macros in Word. What I want to do is when the file is open
fill in a cell in a table with the current date. In access there are events
that I would use to do this. Is there something similar in Word? Or is
there a way to enter a formula in the cell and then protect it? I know, very
basic questions but you only know what you know. If someone could help me I
would be thankful.
Sarah
 
F

Fumei2 via OfficeKB.com

Something you did not mention...

If there is a date already there, do you want it cleared? In other words, do
you always want whatever is the current contents REPLACED with the current
date?

Is there any other text there?

Private Sub Document_Open()
Dim r As Range
Set r = ActiveDocument.Tables(1).Cell(2, 2).Range
With r
.Text = ""
.Collapse 1
.InsertDateTime DateTimeFormat:="dddd, MMMM dd, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
End With
End Sub

The above REPLACES the entire content of Cell(2,2) - second row, second
column - with the current date AS TEXT - it is not an updating field - in the
format of:

Tuesday, January 26, 2010 ("dddd, MMMM dd, yyyy")

On the other hand, if you want the cell to always be the current date (rather
than executing actions on Document_Open) you could simply put in a date field,
and have it update automatically. In which you will see (with Field Codes
visible):

{ DATE \@ "dddd, MMMM dd, yyyy }

No macro required.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top