Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
terrusie
Contributor II
Contributor II

Export all list box columns to csv

Hi all,

Just looking for a way to program a Macro to export all columns of a list box to a csv file.

I tried:

set ExportObject = ActiveDocument.GetSheetObject(ObjID) 

ExportObject.Export FileName, ", " 

but this seems to only export the first column.

1 Solution

Accepted Solutions
tamilarasu
Champion
Champion

Hi Terry,

Great. Here is the macro code to do the same. Also, If you can post the vbs code here, it may help someone someday.

Sub CSVTEST

    

   'File path & name

    vFile = "C:\Users\Tamil\Desktop\MyFile"

   'Export to xls format

   set ExportObj = ActiveDocument.GetSheetObject("LB01")

   ExportObj.Exportbiff vFile & ".xls"

 

   'Convert from xls to csv format

   Set objExcel = CreateObject("Excel.Application")

   objExcel.Visible = False 

   objExcel.Workbooks.Open(vFile & ".xls")

   objExcel.Activeworkbook.Saveas vFile & ".csv", 6

   objExcel.quit

 

   'Delete xls file

   Set Filesys = CreateObject("Scripting.FileSystemObject")

   Filesys.DeleteFile vFile & ".xls"

   Set objExcel = Nothing

   Set Filesys = Nothing

 

   Msgbox "File has been created!"

End Sub

View solution in original post

15 Replies
vishsaggi
Champion III
Champion III

Check here if this helps:

Macro csv export | Qlik Community

balabhaskarqlik

May be this:

Sub ExportToCSV

Set ExportObject = ActiveDocument.GetSheetObject("(ObjectCode)")

ExportObject.Export "(FileAdress)\(FileName).csv", ";"

End Sub

terrusie
Contributor II
Contributor II
Author

This works great for a chart, but when I use it with a listbox, I only get the first column.  Is there something I'm doing wrong?

terrusie
Contributor II
Contributor II
Author

This works great for a chart, but when I use it with a listbox, I only get the first column.  Is there something I'm doing wrong?

tamilarasu
Champion
Champion

Hi Terry,

What do you mean by all columns? Could you explain your requirement bit more clearer. If possible attach a sample and expected output.

terrusie
Contributor II
Contributor II
Author

Tamil,

Apologies for not being clear.  The listbox has several expressions, but when I use the code above on the listbox, only the data in the initial field show up.  None of the data from the expressions show up.  For some reason charts produce the expected result, but not listboxes.   Unfortunately, the data in my listbox cannot be charted.  It contains textual data.

Example:

Listbox:

------------------------------------------------------------------------------------------------

Field datum 1     |     Expression 1 datum 1     |     Expression 2 datum 1

Field datum 2     |     Expression 1 datum 2     |     Expression 2 datum 2

Field datum 3     |     Expression 1 datum 3     |     Expression 2 datum 3

-------------------------------------------------------------------------------------------------



Actual CSV Output:


Field datum 1    

Field datum 2    

Field datum 3



Expected CSV Output:


Field datum 1, Expression 1 datum 1, Expression 2 datum 1

Field datum 2, Expression 1 datum 2, Expression 2 datum 2

Field datum 3, Expression 1 datum 3, Expression 2 datum 3

   





tamilarasu
Champion
Champion

Hi Terry.

There is no need to apologize . We just want some clear input to help you further.  Now, I understood your question. I have one more request. Is it possible to attach one sample qvw file? It will be really easy for us to test and provide you the solution.

terrusie
Contributor II
Contributor II
Author

Tamil,

Unfortunately, I cannot.  I do not yet have a pro-license seat.  I will soon, perhaps, but not as of yet.

terrusie
Contributor II
Contributor II
Author

To reproduce my problem, simply use the code suggested by Bala, above, on a listbox that has a calculated field and at least one expression.  I'm sure you will get the same results.