Invoke VBA: Cannot run the macro 'CleanSheet2'. The macro may not be available in this workbook or all macros may be disabled

Hi all,

I’m trying to invoke two VBA in the UiPath workflow, and the wording is pretty much the same. But an error would occur when I try to invoke my second workflow. Do you know why?

Invoke VBA Activity 1:
Sub CleanSheet1()

' Declare variables
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")

' Clear contents of sheet
ws.Cells.ClearContents

' Convert cells to text format
ws.Cells.NumberFormat = "@"

End Sub

Invoke VBA Activity 2:
Sub CleanSheet2()

' Declare variables
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet2")

' Clear contents of sheet
ws.Cells.ClearContents

' Convert cells to text format
ws.Cells.NumberFormat = "@"

End Sub

@Paddi

  1. Are the macros saves in a vba or text files and from there you are invoking them?
  2. Or are you using execute macro and the macros are presnrt in a workbook?

Can you please show how you implemented…

Cheers

@Anil_G,

The macros are saved in txt files, and I used a invoke VBA activity to use the txt file.

@Paddi

Please check the name of the macro if you provided exactly same as I dont see an issue here

Or please show the screenshot of bot the text file and the UiPath studio where you are invoking

And also you need not use teo different for this use an argument in place of sheets like below


Sub CleanSheet2(WBSheet as String)

' Declare variables
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(WBSheet)

' Clear contents of sheet
ws.Cells.ClearContents

' Convert cells to text format
ws.Cells.NumberFormat = "@"

End Sub

And in invoke vba you can pass the sheetname value as input

Cheers

@Anil_G Thank you, the problem seems to be solved by deleting all the saved macro in my excel file. Many thanks anyway.

1 Like