I have a VBA vode in a text file (contains some formatting steps on a worksheet)
The flow generates az Excel output and I would like to use Invoke VBA to do the formatting.
I got no error but the flow is freezin at the Invoke VBA step and I need to stop manually.
Is that normal behaviour or do I need to enable VBA?
If yes, how to enable VBA in an Excel generated by UiPath?
@erika027
Make sure macros are enabled in Excel. To do this, open Excel, go to File → Options → Trust Center → Trust Center Settings → Macro Settings, and select Enable all macros.
Ensure the VBA code is correct and does not contain errors. You can test the VBA code directly in Excel before using it in UiPath
This Excel is generated during execution just like Invoke VBA step. File → Options → Trust Center → Trust Center Settings → Macro Settings, and select Enable all macros. I can not do it during execution.
Enable all macros (not recommended, potentially dangerous code can run) All macros run without confirmation. This setting makes your computer vulnerable to malicious code.
In Excel this option is Enable VBA macros (not recommended, potentially dangerous code can run) and it only applies to VBA macros.
This option would enable macros for all file so should work in theory for files genarated by UiPath you can give it a try.
Another way you could do is create a template file with macros enabled copy that file whenever the project executes make your changes to that file. It should execute your macros
Sub color()
ActiveSheet.Range("A1:E11").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Your’s is working perfect for me
Manually create an excel and enable trust centre then check colouring the cells in excel
Sub color()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("YourSheetName") ' Replace YourSheetName with the name of your sheet
With ws.Range("A1:E11").Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Try to place your text file within your project folder. Make sure you give correct method name. If the excel should be created at run time please check the tick mark Create If not Exists and try once.
While during the execution you cannot do this steps, stop your bot in Studio. Open Task manager and kill the excel application. Then give one more try. If you are getting any exception send us the exception details.