Setting decimal align in a Word table

I have selected the cells in a Word table that I am filling using VB6.  What I am having trouble doing is declaring the selection variable and then setting it.  I think the selection statement is correct but I get an error 91 -- Object variable or With block variable not set.  I would appreciate some sample code.  Thanks.
LVL 1
rkulpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Stephen MandersonSoftware EngineerCommented:
What code are you using to fill the word table ?

Manderson
0
rkulpAuthor Commented:
Here is a fragment of the code.  The object oTable was dimensioned earlier.

Dim R As Integer, c, NbrColumns As Integer
Select Case ReportCode
    Case 1  'Internal Reports -- These have 9 columns
        Set oTable = oDoc.Tables.add(oDoc.Bookmarks("\endofdoc").Range, AuditInfo.NbrStrata + 2, 9)
        NbrColumns = 9
    Case 2  'Auditor Reports -- These have 8 or 9, depending on parameters set in PrintOptions.
        If frmPrintOptions.chkARStdDev.Value = True Then
            Set oTable = oDoc.Tables.add(oDoc.Bookmarks("\endofdoc").Range, AuditInfo.NbrStrata + 2, 9)
            NbrColumns = 9
        Else
            Set oTable = oDoc.Tables.add(oDoc.Bookmarks("\endofdoc").Range, AuditInfo.NbrStrata + 2, 8)
            NbrColumns = 8
        End If
    Case 3  'Taxpayer Reports -- These have 8 or 9, depending on parameters set in PrintOptions
        If frmPrintOptions.chkTRStdDev.Value = True Then
            Set oTable = oDoc.Tables.add(oDoc.Bookmarks("\endofdoc").Range, AuditInfo.NbrStrata + 2, 9)
            NbrColumns = 9
        Else
            Set oTable = oDoc.Tables.add(oDoc.Bookmarks("\endofdoc").Range, AuditInfo.NbrStrata + 2, 8)
            NbrColumns = 8
        End If
End Select

oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Range.Font.Size = 11
oTable.Rows(1).Range.Font.Bold = True
R = 1
c = 1
oTable.Columns(c).Width = oWord.InchesToPoints(0.75)
oTable.Cell(R, c).Range.Text = "Stratum"
c = 2
oTable.Columns(c).Width = oWord.InchesToPoints(1)
oTable.Cell(R, c).Range.Text = "Lower Boundary"
c = 3
oTable.Columns(c).Width = oWord.InchesToPoints(1)
oTable.Cell(R, c).Range.Text = "Upper Boundary"
c = 4
oTable.Columns(c).Width = oWord.InchesToPoints(1.5)
oTable.Cell(R, c).Range.Text = "Total Errors"
c = 5
oTable.Columns(c).Width = oWord.InchesToPoints(0.75)
oTable.Cell(R, c).Range.Text = "Sample Size"
c = 6
oTable.Columns(c).Width = oWord.InchesToPoints(1.25)
oTable.Cell(R, c).Range.Text = "Average Error"
c = 7
oTable.Columns(c).Width = oWord.InchesToPoints(1)
oTable.Cell(R, c).Range.Text = "Stratum Size"
c = 8
oTable.Columns(c).Width = oWord.InchesToPoints(1.25)
oTable.Cell(R, c).Range.Text = "Projected Assessment"
If NbrColumns = 9 Then
    c = 9
    oTable.Columns(c).Width = oWord.InchesToPoints(1.25)
    oTable.Cell(R, c).Range.Text = "Sample Standard Deviation"
End If

For R = 1 To AuditInfo.NbrStrata
oTable.Rows(R + 1).Range.Font.Bold = False
oTable.Cell(R + 1, 1).Range.Text = R
oTable.Cell(R + 1, 2).Range.Text = Format$(StratSum.Lower(R), "$#,###,##0.00")
'oTable.Cell(R + 1, 2).Select

oTable.Cell(R + 1, 3).Range.Text = Format$(StratSum.Upper(R), "$#,###,##0.00")
oTable.Cell(R + 1, 4).Range.Text = Format$(AsmtResults.StratumError(R), "$###,##0.00")
oTable.Cell(R + 1, 5).Range.Text = Format$(AsmtResults.Nh(R), "#,###")
oTable.Cell(R + 1, 6).Range.Text = Format$(AsmtResults.XBarh(R), "$#,##0.000000")
oTable.Cell(R + 1, 7).Range.Text = Format$(AuditInfo.Nh(R), "###,##0")
oTable.Cell(R + 1, 8).Range.Text = Format$(AsmtResults.StratumAsmt(R), "$##,###,##0.00")
If NbrColumns = 9 Then
oTable.Cell(R + 1, 9).Range.Text = Format$(AsmtResults.SH(R), "$##,##0.00")
End If
Next R
R = AuditInfo.NbrStrata + 1
oTable.Cell(R + 1, 1).Range.Text = "Totals"
oTable.Cell(R + 1, 4).Range.Text = Format$(AsmtResults.TotalError, "$#,###,##0.00")
oTable.Cell(R + 1, 5).Range.Text = Format(AsmtResults.TotalSamsize, "##,###")
oTable.Cell(R + 1, 7).Range.Text = Format$(AuditInfo.NN, "##,###,##0")
oTable.Cell(R + 1, 8).Range.Text = Format$(AsmtResults.TotalAssessment, "$##,###,##0.00")
If NbrColumns = 9 Then
oTable.Cell(R + 1, 9).Range.Text = Format$(AsmtResults.CombinedStdDev, "$##,##0.00")
End If
0
GrahamSkanRetiredCommented:
It's still not clear what difficulty you are having.

The Selection object cannot be declared. There is only one for the whole application.

The Select method applies to a Range, so if this line
      'oTable.Cell(R + 1, 2).Select
was causing the error, it should be
      oTable.Cell(R + 1, 2).Range.Select

Do you really need to use the Selection object? You seem to be working with Ranges, even if not with any Range Objects.
If you need to, you could declare and set a range object this way:
dim rng as range
set rng = oTable.Cell(R + 1, 2).Range

If you want to align a cell to the right, you can do this:
oTable.Cell(R + 1, 2).Range.ParagraphFormat.Alignment = wdAlignParagraphRight



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rkulpAuthor Commented:
This does not completely solve my question but will suffice for the table I am filling since I force the number of decimals to be the same for all entries in a column.  However, even with oTable.Cell(R+1,2).Range.Select I still get error 91 that the object or with variable is not set. Hence I cannot do the selection with tab set to decimal align.

Please consider this solved.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.