Inconsistant Macro Exceptiong while Running with BOT


We are trying to run BOT which is consists of a macro. To run that macro we are just clicking on a button(available on excel sheet) which invokes macro internally which pulls data from database and paste it on different sheets of same excel.

It is working exactly as per expectation but sometimes it throws an error like while pasting graphs from one sheet to another
“Runtime Error 1004 Microsoft excel can not paste the data”

When we tried to run manually , we had never faced this exception, This is very inconsistent exception message which we are getting.

Exception is occurring on below macro code

We are struggling with this issue, please let us know in case if you have any idea or workaround.

Thanks in advance

Is your graph a picture or a chart?


ActiveSheet.ChartObjects("Your Chart").Activate
ActiveChart.Copy Destination:=Worksheets("Sheet").Range("Cells")

EDIT: Actually - how many instances of excel do you have open? Try closing all instances and then running the bot which executes the macro, it may be due to multiple instances of excel open.

Hi CBlanchard,

Thanks for your reply.
We are trying to copy Charts in macro code and we have only 1 excel file instance

Have you tried using invoke code (might be invoke VBA) within the excel application scope instead of trying to fire the macro within excel?

Macro code is already written by another team which is very lengthy and we are just clicking on RUN button which is available on excel sheet which internally invoke macro.
Same is running perfectly fine when we are running manually, but it throws that error sometime. occurrences of error is also inconsistent.
“Runtime Error 1004 Microsoft excel can not paste the data”

So this error happens when you run the macro manually as well?

Without being able to see the macro code it self I don’t think you’ll be able to solve this one. It could be multiple issues.

Manually it is working fine but when we are running with BOT then sometimes we are getting that exception

Select is unreliable when copy and pasting data.

Suggest getting the developers of the macro code to change it to another option. Unfortunately you won’t be able to get around this issue with select.

For more information see here: How to avoid using Select in Excel VBA - Stack Overflow