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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to export data to excel via macro to different worksheets

Hi, I need to export via macro a graphic and a straight table, but in different worksheets. I have the following code:


Sub to_excel
Dim wsname
Set XLApp = CreateObject("Excel.Application")
XLApp.Visible = TRUE
Set XLDoc = XLApp.Workbooks.Add
wsname = ""
wsname = "Sheet1"

strFileName = "C:\Temp\Example.xls"

ActiveDocument.ClearAll True
ActiveDocument.Fields("Year").Select ("2009")
ActiveDocument.Fields("Month").Select ("Aug")
set obj = ActiveDocument.GetSheetObject("CH585")
obj.CopyBitmapToClipboard
XLDoc.Sheets(wsname).Range("A7").Select
XLDoc.Sheets(wsname).Paste
ActiveDocument.GetApplication.WaitForIdle

'I want this part to be in another worksheet, I tried to add one but it doesn't work

ActiveDocument.GetApplication.WaitForIdle
ActiveDocument.GetSheetObject("CH259").CopyTableToClipboard true
XLDoc.Sheets(wsname).Columns("B").ColumnWidth = 40
XLDoc.Sheets(wsname).Range("A" & 1).Select
XLDoc.Sheets(wsname).Paste

end sub


Labels (1)
1 Solution

Accepted Solutions
dirk_konings
Creator III
Creator III

add this to the script before the first scriptline off 'sheet2'

XLDoc.Sheets(wsname2).activate

View solution in original post

2 Replies
dirk_konings
Creator III
Creator III

add this to the script before the first scriptline off 'sheet2'

XLDoc.Sheets(wsname2).activate

Not applicable
Author

Thank you Dirk! it worked