Are you able to modify the macro?
If so, you could surround your code with an error-handling routine.
You can find more info in the following links:
On Error statement (VBA) | Microsoft Learn
VBA Excel simple Error Handling - Stack Overflow
You could also extract the macro’s code, but this might not be ideal depending on your particular situation.
Essentially, VBA is a language that connects to the Excel object library. PowerShell is also a language that can connect to Excel object library. Still others including Java, C#, Python, PHP, R, and more have this facility via Component Object Model (COM) available in Windows environments.
excel - How to use VBA Code inside a Powershell Script - Stack Overflow