I am using automation with MS Word 2007 to open a .docx and send some string data to it for printing purposes. I cannot figure out how to insert the current date and time on the document at runtime (from VB form code). There is a insertdatetime() function, but I don't know how to send parameter. In the code below...for 'opara2', there is a line where I display the string "generated on" and then after that is where I want Word to insert the current date. Can anyone help??


Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
Dim oPara3 As Word.Paragraph, oPara4 As Word.Paragraph
Dim oRng As Word.Range
Dim oShape As Word.InlineShape


oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add

oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "YOUR LUCKY NUMBERS"
oPara1.Range.Font.Color = Word.WdColor.wdColorBlue
oPara1.Range.Font.Bold = True
oPara1.Range.Font.Size = 36
oPara1.Format.SpaceAfter = 12
oPara1.Range.InsertParagraphAfter()

oPara2 = oDoc.Content.Paragraphs.Add
oPara2.Range.Text = "Generated on " &
oPara2.Range.Font.Color = Word.WdColor.wdColorRed
oPara2.Range.Font.Bold = True
oPara2.Range.Font.Size = 36
oPara2.Format.SpaceAfter = 24 '24 pt spacing after paragraph.
oPara2.Range.InsertParagraphAfter()