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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
pgalvezt
Specialist
Specialist

Paste method of Worksheet class failed

Hello, When I try to export my chart into the file excel. The macro paste my last selection. I don´t know why happen this.

Thanks!

7 Replies
pgalvezt
Specialist
Specialist
Author

Hello!

Anyone can help me with this pls?

Thanks!

pgalvezt
Specialist
Specialist
Author

Any Ideas?

Miguel_Angel_Baeyens

Hi,

The you need to activate the object before copying it to the clipboard. Using your code and cleaning it up a bit

Sub print_excel()


     Dim kost
     Set XLApp = CreateObject("Excel.Application")
     XLApp.Visible = true
     Set XLDoc = XLApp.Workbooks.Add
     kost = "Sheet1"
                      
     Set obj = ActiveDocument.GetSheetObject("CH12")       'To Copy  text object as image
     obj.Activate '' you need this line to make this the most recent object selected
     obj.CopyBitmapToClipboard
     XLDoc.Sheets(kost).Range("H2").Select
     XLDoc.Sheets(kost).Columns("G").ColumnWidth = 9
     XLDoc.Sheets(kost).Paste

        
End Sub

Hope that helps.

Miguel

pgalvezt
Specialist
Specialist
Author

Hello Miguel, its rare but the macro paste the last selection that I have had. For Example I pasted your code put into the macro module, execute and appear an Excel with your code and not the chart.

The macro paste this:

Sub print_excel()

     Dim kost
     Set XLApp = CreateObject("Excel.Application")
     XLApp.Visible = true
     Set XLDoc = XLApp.Workbooks.Add
     kost = "Sheet1"
                      
     Set obj = ActiveDocument.GetSheetObject("CH12")       'To Copy  text object as image
     obj.Activate '' you need this line to make this the most recent object selected
     obj.CopyBitmapToClipboard
     XLDoc.Sheets(kost).Range("H2").Select
     XLDoc.Sheets(kost).Columns("G").ColumnWidth = 9
     XLDoc.Sheets(kost).Paste
        
End Sub

pgalvezt
Specialist
Specialist
Author

Why happens that? I've tried all ways to export but its not working.

Miguel_Angel_Baeyens

Hi,

I missed some part yesterday, the code above was working in some cases because it was pasting the chart from previous attemps. Certainly, you (the button that triggers the macro) need to be in the same sheet where the object is to copy it to the clipboard, I don't know if that's the expected behavior or not.

It doesn't work even when you activate the sheet where the object is, if the button is placed in another sheet. As far as I have tested, it exports fine, but it does not copy the image to the clipboard.

But it came to my mind some code provided by Stefan Walther from QlikTech in his blog you can use for that. Check here on how to use it. I'll keep checking that behavior

Hope that helps.

Miguel

pgalvezt
Specialist
Specialist
Author

Hi, nice post. Now I need to know if QlikView export from differents sheets to xls files. Until now in my application for each sheet in QlikView I have to put each bottom that export the charts. But what I want is to create a menu where exist just one bottom and export all the entire sheets into the xls files.