Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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
Check here if this helps:
May be this:
Sub ExportToCSV
Set ExportObject = ActiveDocument.GetSheetObject("(ObjectCode)")
ExportObject.Export "(FileAdress)\(FileName).csv", ";"
End Sub
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?
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?
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.
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
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.
Tamil,
Unfortunately, I cannot. I do not yet have a pro-license seat. I will soon, perhaps, but not as of yet.
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.