Results 1 to 6 of 6

Thread: how to put a date on the first page of the document ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    I would do that a bit differently using either a Date (as shown below) or CreateDate field:

    Sub InsertDateWatermark()
    Dim oHeader As HeaderFooter
    Dim oShp As Shape
    Dim oFld As Field
    Dim oShpRng As ShapeRange
      ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
      Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage)
      For Each oShp In oHeader.Shapes
        If oShp.Name = "Psuedo Date Watermark" Then
          'Watermark already exists.
          oShp.TextFrame.TextRange.Fields(1).Update
          GoTo lbl_Exit
          Exit For
        End If
      Next oShp
      'Insert an appropriately sized basic shape (rectangle)
      Set oShp = oHeader.Shapes.AddShape(msoShapeRectangle, 1, 1, 350, 100)
      With oShp
        'Name and format the shape appearance.
        .Name = "Psuedo Date Watermark"
        .IncrementRotation -45
        .Line.Visible = msoFalse
        .Fill.Visible = msoFalse
      End With
      'Add a DATE field to the shape text frame.
      Set oFld = oShp.TextFrame.TextRange.Fields.Add(oShp.TextFrame.TextRange, wdFieldEmpty, "DATE \@ ""MMMM d, yyyy""")
      'Format the text range.
      With oShp.TextFrame.TextRange
        .Font.Size = 24
        .Font.ColorIndex = wdGray25
      End With
      'Position the shape independent of any other shape in the header.
      Set oShpRng = oHeader.Shapes.Range("Psuedo Date Watermark")
      With oShpRng
        .Align msoAlignCenters, True 'relative to document edges.
        .Align msoAlignMiddles, True
      End With
    lbl_Exit:
      Exit Sub
    End Sub
    Sub RemoveDateWatermark()
    Dim oRng As Range
    Dim oHeader As HeaderFooter
    Dim oShp As Shape
      Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage)
      For Each oShp In oHeader.Shapes
        If oShp.Name = "Psuedo Date Watermark" Then
          oShp.Delete
          Exit For
        End If
      Next oShp
    lbl_Exit:
      Exit Sub
    End Sub
    Last edited by gmaxey; 11-05-2015 at 04:05 AM.
    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
  •