Submitted by JXB on Sat, 12/06/2014 - 06:38
Forums:
To all,
I am writing a small macro which seems to work. I am now trying to see where "error" can occur if something (an "NX Action") is not successful. For example I have the following line
theSession.DataManager.LoadFile(pathAFUFile)
which works fine because I know that the afu file exists
What is the best of capturing "elegantly" the fact that the macro will crash if the afu does not exit. Is it one of does Try..Catch syntax?
Any help in expanding my vba knowledge is welcome
Thanks
Regards
JXB
re: check that file exists
The .NET framework has functions for working with files and directories. You can check that a specified file exists with the IO.File.Exists() function:
If IO.File.Exists({path to file}) Then
'open file
Else
'skip processing, warn user, etc.
End If
RE: Check if an NX "action" has been done successfully-How to?
Thanks for that. Just used the 'File.Exist' in another macro (!). While I understand the idea of checking if the .afu file exists before doing the 'LoadFile' action my question was more general. Can one have the following scenario? The .afu exists but the LoadFile "Action" is not successful (I do not know if it's possible/realistic). Is there a way of catching this "gracefully"?
Thanks
Regards
JXB
Thanks
Regards
re: file load error
I'd recommend placing the statement(s) that load the file in a Try block. This will allow you to catch and handle any errors that occur.