Waubain
02-26-2012, 09:00 PM
This is my first attempt with Word VBA. I am trying to automate a form letter that contains a table. I want to fill in the first column of the table with dates starting at Row(3). DTPickerProcedure, cboPreDays, and cboPostDays all come from a user form. This routine is a part of a larger routine, and variables are declared earlier.
I am receiving an "Invalid use of the Property" at .Cells in the following line of code
ActiveDocument.Tables(1).Rows(3).Cells
I know the routine has more problems because it is not going to count properly the way it is written but I cannot get pass the error.
The way is should work is if
DTPickerProcedure.Value = 3/5/2012
cboPredays = 2
cboPostday = 2
The dates starting at row(3) should be
cell(3,1) 3/3/2012
cell(4,1) 3/4/2012
cell(5,1) 3/5/2012
cell(6,1) 3/6/2012
cell(7,1) 3/7/2012
Here is what I have so far:
Private Sub FillDateColumn()
Dim intPreDays As Integer
Dim intPostDays As Integer
Dim intCounter As Integer
Dim irows As Integer
intPreDays = cboPreDays.Value
intPostDays = cboPostDays.Value
irows = (intPreDays + intPostDays + 1)
For intCounter = 1 To irows
ActiveDocument.Tables(1).Rows(3).Cells
Cell(1).Range.Text = DateAdd("d", -(intPreDays), DTPickerProcedure.Value)
Next
End Sub
I need the date output to be in this format, but that is not the primary problem.
Format(DTPickerProcedure.Value, "dddd, mmmm d, yyyy")
Thanks for any suggestions.
I am receiving an "Invalid use of the Property" at .Cells in the following line of code
ActiveDocument.Tables(1).Rows(3).Cells
I know the routine has more problems because it is not going to count properly the way it is written but I cannot get pass the error.
The way is should work is if
DTPickerProcedure.Value = 3/5/2012
cboPredays = 2
cboPostday = 2
The dates starting at row(3) should be
cell(3,1) 3/3/2012
cell(4,1) 3/4/2012
cell(5,1) 3/5/2012
cell(6,1) 3/6/2012
cell(7,1) 3/7/2012
Here is what I have so far:
Private Sub FillDateColumn()
Dim intPreDays As Integer
Dim intPostDays As Integer
Dim intCounter As Integer
Dim irows As Integer
intPreDays = cboPreDays.Value
intPostDays = cboPostDays.Value
irows = (intPreDays + intPostDays + 1)
For intCounter = 1 To irows
ActiveDocument.Tables(1).Rows(3).Cells
Cell(1).Range.Text = DateAdd("d", -(intPreDays), DTPickerProcedure.Value)
Next
End Sub
I need the date output to be in this format, but that is not the primary problem.
Format(DTPickerProcedure.Value, "dddd, mmmm d, yyyy")
Thanks for any suggestions.