Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

VBScript macro to export multiple tables to one csv file

Hi

I want to export multiple tables into one csv file but manage to keep the headers or have a way to differentiate between them in the output file. I am using the code below:

Sub ExportToExcel

          'Get the table we want to export

          Set t1 = ActiveDocument.GetSheetObject("CH51")

          t1.Export "tables.txt", ","

          Set t2 = ActiveDocument.GetSheetObject("CH52")

          t2.Export "tables.txt", ",", , TRUE

End Sub

Unfortunatelly what this does is to export the headers only from the first table and ignores the second. Is there any way that I can write a blank line between tables or at least write all the headers?

Cheers

D

1 Reply
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You can add a bit of code to open the file and append some text in between. Something like this maybe:

Sub ExportToExcel

          'Get the table we want to export

          Set t1 = ActiveDocument.GetSheetObject("CH51")

          t1.Export "tables.txt", ","

          Set objFSO = CreateObject("Scripting.FileSystemObject")

          Set objTextFile = objFSO.OpenTextFile ("tables.txt", 8, True)

          objTextFile.WriteLine("")
          objTextFile.Close

         

          Set t2 = ActiveDocument.GetSheetObject("CH52")

          t2.Export "tables.txt", ",", , TRUE

End Sub


talk is cheap, supply exceeds demand