Steven Reid
asked on
Object variable or With block variable not set error when trying to use Selection in Access 2010 vba
Hi All,
I am updating a word document from Access 2010 and am coming up against a "Object variable or With block variable not set" error when I try to format a column in a table.
I am using the following code:
and I receive the "Object variable or With block variable not set" when I get to the
Any help greatly appreciated!
I am updating a word document from Access 2010 and am coming up against a "Object variable or With block variable not set" error when I try to format a column in a table.
I am using the following code:
Sub FormatTable(tbl As Word.Table)
'Variable declaration
Dim cel As Word.Cell
Dim s As String
'Bold the header row
With tbl.Rows(1).Range.Font
.Bold = True
.Underline = wdUnderlineSingle
End With
'Center the last column
tbl.Columns(tbl.Columns.Count).Select
For Each cel In Selection.Cells
cel.Range.Paragraphs.Alignment = wdAlignParagraphCenter
Next cel
tbl.Columns.AutoFit
tbl.Borders.Enable = False
End Sub
and I receive the "Object variable or With block variable not set" when I get to the
For Each cel In Selection.Cells
line.Any help greatly appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much!