Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
geogou1973
New Contributor II

ActiveDocument.GetSheetObject("CH01") and read the fields

Hello.

How can i read the values of a field of a sheet object in a vbscript module ?

sub test

SET Doc = ActiveDocument.GetSheetObject("CH01")

set Field = Doc.Fields("STORE_ID").GetPossibleValues

FOR i=0 to Field.Count -1

Doc.Fields("STORE_ID").SELECT Field.Item(i).Text

msgbox(Field)

next

end sub

This script does not work.

Can anyone help me ?

Thank you in advance.

1 Solution

Accepted Solutions
mov
Esteemed Contributor III

Re: ActiveDocument.GetSheetObject("CH01") and read the fields

Your macro reads field values, but you need to read from the chart directly.  Replace macro with this:

Sub TEST

set obj = ActiveDocument.GetSheetObject( "CH01" )
CellRect = ActiveDocument.GetApplication().GetEmptyRect()
CellRect.Top = 0
CellRect.Left = 0
CellRect.Width = obj.GetColumnCount
CellRect.Height = obj.GetRowCount
set CellMatrix = obj.GetCells( CellRect )
for RowIter=CellRect.Top+1 to CellRect.Height-1
        msgbox(CellMatrix(RowIter)(ColIter).Text)
next  
End sub

Regards,

Michael

8 Replies
MVP
MVP

Re: ActiveDocument.GetSheetObject("CH01") and read the fields

Hi,

Can you attach sample file and expected result, it helps in providing solution easily.

Regards,

Jagan.

geogou1973
New Contributor II

Re: Re: ActiveDocument.GetSheetObject("CH01") and read the fields

I want to read the values of the fields of the sheet object CH01

giakoum
Honored Contributor II

Re: ActiveDocument.GetSheetObject("CH01") and read the fields

SUB ShowValues

set CntValues = ActiveDocument.fields("Activity1").getPossibleValues

  for i=0 to CntValues.Count - 1

  a = CntValues.Item(i).Text

  msgbox(a)

  next

end sub

geogou1973
New Contributor II

Re: Re: ActiveDocument.GetSheetObject("CH01") and read the fields

Sorry the file that i uploaded was not correct.

If you see the script reads all the values.

I want to read only the values that are in the chart.

mov
Esteemed Contributor III

Re: ActiveDocument.GetSheetObject("CH01") and read the fields

Your macro reads field values, but you need to read from the chart directly.  Replace macro with this:

Sub TEST

set obj = ActiveDocument.GetSheetObject( "CH01" )
CellRect = ActiveDocument.GetApplication().GetEmptyRect()
CellRect.Top = 0
CellRect.Left = 0
CellRect.Width = obj.GetColumnCount
CellRect.Height = obj.GetRowCount
set CellMatrix = obj.GetCells( CellRect )
for RowIter=CellRect.Top+1 to CellRect.Height-1
        msgbox(CellMatrix(RowIter)(ColIter).Text)
next  
End sub

Regards,

Michael

geogou1973
New Contributor II

Re: ActiveDocument.GetSheetObject("CH01") and read the fields

It is working.

Thank you very much

geogou1973
New Contributor II

Re: ActiveDocument.GetSheetObject("CH01") and read the fields

Michael how can i read the other fields also ?

I can not understand the code.

mov
Esteemed Contributor III

Re: ActiveDocument.GetSheetObject("CH01") and read the fields

The macro above is a slightly modified version of this one from the API Guide, which cycles through both rowns and columns, and starts from the header row:

set obj = ActiveDocument.GetSheetObject( "CH01" )

CellRect = ActiveDocument.GetApplication().GetEmptyRect()

CellRect.Top = 0

CellRect.Left = 0

CellRect.Width = obj.GetColumnCount

CellRect.Height = obj.GetRowCount

set CellMatrix = obj.GetCells( CellRect )

for RowIter=CellRect.Top to CellRect.Height-1

    for ColIter=CellRect.Left to CellRect.Width-1

        msgbox(CellMatrix(RowIter)(ColIter).Text)

    next

next

Open the API Guide, take a look.

Regards,

Michael

Community Browser