Execute macro does not run as expected

Hi,

I have a macro in Excel that inserts a new sheet based on the excisting sheet but when I run it from Studio using Execute Macro activity I get a blank sheet. It is the first part of the code that goes wrong - the copy is not excuted properly.

The VBA code is:

Why are you trying to do this with a macro instead of the UiPath Excel activities?

Because it is part of other macros running in Excel and I do not want to do small pieces from UiPath. The question here is why calling the macro from UiPath is not working properly

That’s best practice, though. The only time you should use macros is when you can’t accomplish the task with UiPath activities. Macros, as you’re seeing, are unreliable and complicated - and will be difficult for others to interpret, support, and modify in the future.

Anyway, if you run the macro directly from Excel does it work?

Yes, when running the macro from Excel it works without problems. Makes a copy of the old sheet and prepares it for a new year.

Regarding your comment about doing everything from UiPath I agree but find it difficult to achieve with macros in Excel.

The Write Range activity will create a new sheet for you if the sheet name you give it doesn’t exist. Very simple way to copy a sheet. Read Range from “Sheet Name A” and Write Range to “Sheet Name B” - if “Sheet Name B” doesn’t exist it’ll be created.

So you want me to use UiPath, but what do I do when my macro is called from within Excel and then part of it is in UiPath?

So the conclusion is that Execute macro activity in UiPath is unstable and does not work? What is then the purpose of having it?

Why would your macro be called from within Excel? Aren’t you building an automation? What is your goal here?

I have macros running in Excel. Then I build RPA using UiPath that is getting data to the Excel sheet and at new year making a new sheet. So I do not want to rebuild all my macros to UiPath because it would take 100+ hours.

I just want to be able to run a macro from UiPath but obviously UiPath is not able to do that properly

Found the error!

Before calling the macro from UiPath I was using an Excel activity FindFirstLastRow in UiPath. This activity creates an empty sheet and throws an error if the sheet does not excist in Excel. So because an empty sheet was created my Excel macro could not run properly and the result was an empty sheet.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.