Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikviewforum
Creator II
Creator II

How to pick fields of a selected table using macro

Hi,

How to pick all the fields of a table using macro? For example, using the below macro we are able to pick the table name. we would like to pick all fields of the selected table as well. For your information we would like to pick automatically instead of adding the fields one by one.

Can someone please help me out on this.

Thanks,
qvforum

3 Replies
kamalqlik
Partner - Specialist
Partner - Specialist

Hi...but can you tell me that where you want all the table to be filled.

In case you want to get the field in excel ...than you can apply simply as

SUB xport2xl()

          iRow=1

          dim kost,i

          kost =""

          kost = "Sheet1"

          SET xlApp = CreateObject("Excel.Application")

          xlApp.Visible = True

 

          SET xlWB = xlApp.Workbooks.Add

          SET xlSheet = xlWB.Worksheets(1)

          set obj = ActiveDocument.getsheetobject(ChartName)

 

          xlSheet.Activate

          xlSheet.Cells.Clear

 

          SET txt = ActiveDocument.GetSheetObject("CH2637")

          txt.CopyTableToClipboard TRUE

          xlSheet.Cells(iRow,1).Select

          xlSheet.Paste

 

          WHILE NOT (IsEmpty(xlSheet.Cells(iRow,1)))

                    iRow = iRow + 2

          WEND

 

          SET txt1 = ActiveDocument.GetSheetObject("CH2635")

          txt1.CopyTableToClipboard TRUE

          xlSheet.Cells(iRow,1).Select

          xlSheet.Paste

 

          end sub

SUB xport2xl2()

          iRow=1

          dim kost,i

          kost =""

          kost = "Sheet1"

          SET xlApp = CreateObject("Excel.Application")

          xlApp.Visible = True

 

          SET xlWB = xlApp.Workbooks.Add

          SET xlSheet = xlWB.Worksheets(1)

          set obj = ActiveDocument.getsheetobject(ChartName)

 

          xlSheet.Activate

          xlSheet.Cells.Clear

 

          SET txt = ActiveDocument.GetSheetObject("MB02")

          txt.CopyTableToClipboard TRUE

          xlSheet.Cells(iRow,1).Select

          xlSheet.Paste

 

          WHILE NOT (IsEmpty(xlSheet.Cells(iRow,1)))

                    iCol = iCol + 3

          WEND

 

          SET txt1 = ActiveDocument.GetSheetObject("MB03")

          txt1.CopyTableToClipboard TRUE

          xlSheet.Cells(iRow,1).Select

          xlSheet.Paste

          end SUb

regards

kamal

qlikviewforum
Creator II
Creator II
Author

Hi

Once the user selects the table, I want to pick all the fields of the respective table and show it in a table box. I don't want to fill it in excel.

Thanks,
qvforum

kamalqlik
Partner - Specialist
Partner - Specialist

Hi you can try this

Sub Selection_bingo

set f = ActiveDocument.Fields("MyField")

set table = ActiveDocument.GetSheetObject("TB02(Tablebox)")

for RowIter = 1 to table.GetRowCount-1

for ColIter =0 to table.GetColumnCount-1

set myvalues= table.GetCell(RowIter,ColIter)

msgbox(myvalues.Text)

' f.select myvalues

next

next

End Sub..

hope this will help you

or

Sub CreateTable

Set tb= ActiveDocument.Sheets("Main").CreateTableBox

tb.AddField "FieldName1"

tb.AddField "FieldName2"

End Sub

// This is code adding fileds for existing table

Sub CreateTable

Set tb= ActiveDocument.GetSheetObject("TB01")

tb.AddField "FieldName1"

tb.AddField "FieldName2"

End Sub

regards

Kamal