Cannot run Excel macro after Windows legacy migration

Hello,
After migrating one project from Windows Legacy to Windows (Studio version 23.4.5) I’m getting the following error during runtime.
“Invoke VBA AutoFit: Cannot run the macro ‘AutofitAllUsed’. The macro may not be available in this workbook or all macros may be disabled.”

All the macro settings in Excel/Trust Center are correct.
The macro is saved inside the project in a .txt file and is invoked using the “Invoke VBA” activity. It cannot be saved inside the target excel file.
image

Sub AutofitAllUsed()
	Dim x As Integer
	For x = 1 To ActiveSheet.UsedRange.Columns.Count
		 Columns(x).EntireColumn.autofit
	Next x
End Sub

This part is running without errors in Windows Legacy version of the project.

Any help would be greatly appreciated!

Hello @Mugur,

I found this post in the forum : The macro may not be available in this workbook or all macros may be disabled even after modified trust center - #19 by Charbel1

I think it can help you :slight_smile:

Hello @Pierre_Fleury,
The Charbel1 solution doesn’t work in my case because the macro is stored in a .txt file not inside the .xls.
Thanks,
Mugur

Finally I found the error. The .txt file containing the macro was edited using UiPath Studio editor instead of Notepad or Notepad++. This operation invalidates the macro file at runtime

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