Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading cell values from tables

Status
Not open for further replies.

MikeKeane

Programmer
Sep 5, 2001
13
GB
Hi,
can anyone please tell me how to read the cell values from a table structure ( not the provider ) as it appears in a report using VBA?

Thanks
 
Sub Access()
Dim doc As busobj.Document
Dim reps As busobj.Reports
Dim rep As busobj.Report
Dim sectionstruc As busobj.SectionStructure
Dim reportstructureitem As busobj.reportstructureitem
Dim reportstructureitems As busobj.reportstructureitems

Dim blockstruc As busobj.BlockStructure
Dim piv As busobj.Pivot
Dim doc_var As busobj.DocumentVariable
Dim row_var As busobj.DocumentVariable
Dim col_var As busobj.DocumentVariable

Dim doc_vars As busobj.DocumentVariables

Dim var As Variant
Dim j As Integer
Dim n As Integer
Dim i As Integer
Dim p, k As Integer
Dim myarr(5000, 5000) As Variant

Set doc = ActiveDocument
Set rep = doc.Reports.Item("Report1")

Set sectionstruc = rep.GeneralSectionStructure
Set reportstructureitems = sectionstruc.Body

For j = 1 To reportstructureitems.Count
Set reportstructureitem = reportstructureitems.Item(j)
Debug.Print "in j loop"
If reportstructureitem.Type = boTable Then
Set blocstruc = reportstructureitem
'This is essential so that all the properties are inherited
'from the ReportStructureItem to the BlockSructure
End If
Set piv = blocstruc.Pivot

Debug.Print p

For n = 2 To piv.BodyCount
Set doc_var = piv.Body(n)
var = doc_var.Values(BoAllValues)

For i = 1 To 5 ' UBound(var) 'row

'gets values in cells
myarr(i, n) = var(i)
Debug.Print "myarr("; i; ","; n; ") "; myarr(i, n)

Next i
Debug.Print "break"
Debug.Print i
Next n

Debug.Print "before J loop ends"
Debug.Print "first element"; myarr(1, 1)
Debug.Print "after Array printing"
Next j


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top