Solved

# Setting decimal align in a Word table

Posted on 2004-11-19
203 Views
Last Modified: 2010-05-02
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
Question by:rkulp
4 Comments

LVL 19

Expert Comment

What code are you using to fill the word table ?

Manderson
0

LVL 1

Author Comment

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

LVL 76

Accepted Solution

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

LVL 1

Author Comment

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

## Write Comment

Please enter a first name

Please enter a last name

We will never share this with anyone.

## Featured Post

Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

#### 759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!