"file not found" when using Shell()
Forgive if this is a total noob question.
All I want to do is launch an external app (a Perl script) using Shell(). But all I get is "Run-time error '53': File not found."
I even copied the example verbatim from the VB Help:
[VBA]Dim RetVal
RetVal = Shell("Macintosh HD:Applications:Calculator", vbNormalFocus)[/VBA]
Same error. This seems so elementary.
Existence and Error recovery
Hi,
You could check for the existence of the file and/or the path in VBA before you go and run your Perl script, or you can put the checks for existence in the Perl script itself. Then have the VBA macro calling the Perl script do various things depending on the return value from the Perl script.
Generally, I'd go with the first approach simply 'cause it'll result in "cleaner" code.
Also, I would recommend using an Error Handler statement in your VBA to handle any errors encountered while running the macro. Otherwise the end User gets a message from Word they may or may not know what to do with. If the problem is simply the existence of a file or path, then I'd check for the existence of them first, before calling the Perl script. In the case where the indicated file/path doesn't exist, you can pop up a MsgBox on the User's screen alerting them to the situation and let them proceed forward by taking the indicated action. Check out the "On Error" VBA help entry for more details.
A quick boolean test for the existence of a file is:
[VBA]
Function FileExists(Filename As String) As Boolean
On Error Resume Next
FileExists = (Dir$(Filename <> "")
End Function
[/VBA]
Ed