PDA

View Full Version : Display date when loading word document



Greens85
08-30-2016, 05:58 AM
Hi All,

I think this should be a fairly simple one.

I have a word document with a simple table comprising of a few rows and columns. When the word document is opened, I want to have todays date inserted into one of those table cells. Once inserted, the date should not be updated on subsiquent opening of said word document.

I did managed to get the date to auto populate at the top of the document, but I haven't as of yet been able to get it to appear in the cell I need it in.

Can anyone point me in the right direction?

Thanks.

gmaxey
08-30-2016, 06:46 PM
Sub Document_Open()
Dim oRng As Range
Set oRng = ActiveDocument.Tables(1).Cell(1, 1).Range 'Change Table(1) to table whatever. Change Cell(1, 1,) to Cell(Row whatever, Column whatever)
oRng.End = oRng.End - 1
If Not IsDate(oRng) Then
oRng.Text = Format(Now, "dd MMMM yyyy")
End If
End Sub