Consulting

Results 1 to 2 of 2

Thread: Display date when loading word document

  1. #1
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    1
    Location

    Display date when loading word document

    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.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •