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: 
Not applicable

Macro csv export

Hi!

i'm using the below macro to export a qv table into a csv file:

set ExportObject = ActiveDocument.GetSheetObject("CH1011")

ExportObject.Export "QV\Production\QVD\Monitor\Details.csv", "," 

in the table I export (CH1011) there are 5 colums:

id, name, city, country, region

I only want to export the id, city and region columns. how can I do that?

thanks!

8 Replies
luciancotea
Specialist
Specialist

You create a copy of your pivot/table chart and leave only the columns you need. Export this copy..

Move it to a hidden sheet if you don't want to show it.

tamilarasu
Champion
Champion

Hi Naamamor,

Try this code,

Sub Test

Dim objExcel

FileName = "QV\Production\QVD\Monitor\Details.csv"

set ExportObject = ActiveDocument.GetSheetObject("CH1011")

ExportObject.Export FileName, ","

Set XLApp  = CreateObject("Excel.Application")

XLApp.Visible = False

XLApp.Workbooks.Open(FileName)

set XLSheet = XLApp.Worksheets(1)

XLSheet.Range("C:D").Delete

XLApp.DisplayAlerts = False

XLSheet.Saveas FileName

XLApp.DisplayAlerts = True

XLApp.Application.quit 

set ExportObject = Nothiing

set XLSheet = Nothing 

set XLApp = Nothing 

Msgbox "Exported Sucessfully" 

End Sub

tamilarasu
Champion
Champion

Sorry. The correct column reference should be

   XLSheet.Range("C:D").Delete

   XLSheet.Range("B:B,D:D").Delete

Not applicable
Author

thank you Tamil,

i receive this error msg: ActiveX component can't create object: 'Excel.Application'

m_woolf
Master II
Master II

Either macro settings are not set to System Access or Excel isn't installed on the computer.

jerrysvensson
Partner - Specialist II
Partner - Specialist II

He is using WebView and macros that uses CreateObject will not work there. Regardless security settings.

Use your current solution but create another object with only the dimension needed. As Lucian recommended.

tamilarasu
Champion
Champion

Naamamor,

As suggested by mwoolf‌, you must set the requested module security and current local security to "Allow System Access" in macro window.

Untitled.png

hitha1512
Creator
Creator

Hi ,

Could you please help me with a macro to export object data into .csv ?

 

Regards,

Hitha Dhani