Solly,
Accepted
Ok. Here is a slightly refined version of the code I first provided:
Sub AutoExec()
Dim oDoc As Document
Dim oTbl As Word.Table
Dim myArray() As Variant
Dim lngCount As Long
Dim i As Long
If MsgBox("Do you want to generate letters due today?", vbQuestion +
vbYesNo, "Generate Letters") = vbYes Then
'Open the source file. This is a simply Word document with a single table
and 3 columns. Column 1 contains the due date in in "7/18" format. Column
2 is the persons first name
'column 3 is the persons last name.
Set oDoc = Documents.Open(FileName:="C:\Source.doc", Visible:=False)
'Modify file name and path as needed
Set oTbl = oDoc.Tables(1)
lngCount = oTbl.Rows.Count
ReDim myArray(lngCount - 1, 2)
'Load the information from the table into an array.
For i = 0 To lngCount - 1
myArray(i, 0) = Left(oTbl.Cell(i + 1, 1).Range.Text, Len(oTbl.Cell(i +
1, 1).Range.Text) - 2)
myArray(i, 1) = Left(oTbl.Cell(i + 1, 2).Range.Text, Len(oTbl.Cell(i +
1, 2).Range.Text) - 2)
myArray(i, 2) = Left(oTbl.Cell(i + 1, 3).Range.Text, Len(oTbl.Cell(i +
1, 3).Range.Text) - 2)
Next i
oDoc.Close wdDoNotSaveChanges
'Iterage throug each item in the array
For i = 0 To lngCount - 1
'If the date in the array matches the system date then generate a
letter.
If myArray(i, 0) Like Format(Date, "M/dd") Then
'Create a new document based on a birthday letter template
Set oDoc = Documents.Add("F:\My Documents\Word\Templates\My birthday
letter template.dot") 'Modify file name and path as needed.
With oDoc
'Put the part or all of the array information in the new document.
.Range.Text = "Happy birthday to you, happy birthday to you." _
& " Happy birthday dear " & myArray(i, 1) & ", happy birthday to
you!!"
End With
End If
Next i
End If
End Sub
There is a "Contact me" link at the following address:
http://gregmaxey.mvps.org/word_tips.htm