[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

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.
0
rkulp
Asked:
rkulp
  • 2
1 Solution
 
Stephen MandersonCommented:
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
 
GrahamSkanCommented:
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now