Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
mridgley
New Contributor

Looping through filter values and saving the output to a csv file

 

Hello,

 

I have a list box with 14 entries. 

For each selection, I want to:

  1. Select all filters values except one
  2. Run a macro that will
    1. copy a specific table from QlikView (ex. CH1000)

    2. create a csv file and
    3. save the csv file in a folder

    

For example, if I have a list box (Product) with four entries: A, B, C, D I want a macro that

  1. selects Product A, B and C and saves table CH1000 to a csv file

  2. selects Product B, C and D and saves table CH1000 to a csv file
  3. selects Product C, D and A and saves table CH1000 to a csv file

I do not need the code to be dynamic, so I could specify each combination of filters to apply (i.e., ABC, BCD, CDA). But as my VB skills are limited, I am not sure how to implement this. 

I am open to any alternatives beyond VB and appreciate any help!

 

1 Solution

Accepted Solutions
zhadrakas
Valued Contributor

Re: Looping through filter values and saving the output to a csv file

Hello Michael,

Here is a vbscript that will do exactly what you want except that outout Format is xls.

You can Change it to csv if you want.

Change LB01 to your Listbox Name.

Change CH02 to your Chart Name.

Change "Name" to the fieldname of your listbox

Change path.

sub export_to_csv()

ActiveDocument.ClearAll

set lb = ActiveDocument.GetSheetObject("LB01") 'Listbox Name
set ch = ActiveDocument.GetSheetObject("CH02") 'Chart Name
path = "C:\temp\" 'output Path

ActiveDocument.Fields("Name").SelectAll
set values = ActiveDocument.Fields("Name").GetSelectedValues

For i = 0 to ActiveDocument.Fields("Name").GetSelectedValues.Count - 1

ActiveDocument.Fields("Name").Select values.Item(i).Text
ActiveDocument.Fields("Name").SelectExcluded
name_Excel = "All_Except_" & values.Item(i).Text & ".xls"
ch.ExportBiff path & name_Excel 'Export to xls

next

end sub

regards

Tim

2 Replies
zhadrakas
Valued Contributor

Re: Looping through filter values and saving the output to a csv file

Hello Michael,

Here is a vbscript that will do exactly what you want except that outout Format is xls.

You can Change it to csv if you want.

Change LB01 to your Listbox Name.

Change CH02 to your Chart Name.

Change "Name" to the fieldname of your listbox

Change path.

sub export_to_csv()

ActiveDocument.ClearAll

set lb = ActiveDocument.GetSheetObject("LB01") 'Listbox Name
set ch = ActiveDocument.GetSheetObject("CH02") 'Chart Name
path = "C:\temp\" 'output Path

ActiveDocument.Fields("Name").SelectAll
set values = ActiveDocument.Fields("Name").GetSelectedValues

For i = 0 to ActiveDocument.Fields("Name").GetSelectedValues.Count - 1

ActiveDocument.Fields("Name").Select values.Item(i).Text
ActiveDocument.Fields("Name").SelectExcluded
name_Excel = "All_Except_" & values.Item(i).Text & ".xls"
ch.ExportBiff path & name_Excel 'Export to xls

next

end sub

regards

Tim

mridgley
New Contributor

Re: Looping through filter values and saving the output to a csv file

Hi Tim, this worked perfectly! The only change I made was saving the file as ".csv" instead of ".xls" I really appreciated all of your help.