1

I'm trying to run a program with an input file.

Dim command, cfx5_exe_path, cfx_file_folder, cfx_file_name As String

command = cfx5_exe_path & " -cfx " & cfx_file_folder & cfx_file_name & ".cfx "
Shell command

so it gives an error. the resulting value of the command in the debugger is

"c:\"Program Files"\"ANSYS Inc"\v150\CFX\bin\cfx5pre.exe -cfx c:\Users\Username\Arbeit\Programming\A321_tail_flow.cfx"

If I copy-paste that into windows cmd directly and remove first/last quotation signs, then it works perfectly. What is the problem with Shell?

1 Answer 1

1

The documentation says:

If the Shell function successfully executes the named file, it returns the task ID of the started program. The task ID is a unique number that identifies the running program. If the Shell function can't start the named program, an error occurs.

and it gives a small example:

Sub test()
    Dim RetVal
    Dim command As String
    command = "C:\WINDOWS\CALC.EXE"
    RetVal = Shell(command, 1)
End Sub

Here I get Error 53: file not found as calc on Windows 7 resides somewhere else. Do you get this error?

Providing the right path to calc starts the program and returns a unique ID.

However, quoting a part of the correct path will throw the error:

    command = "C:\WINDOWS\""SYSTEM32""\CALC.EXE"

but quoting the full path does not:

    command = """C:\WINDOWS\SYSTEM32\CALC.EXE"""

So you must remove all embedded quotes and then quote the full path once.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I get the same Error 53. Why did you qoute system32? I quoted Program Files as there is a space in the folder name.
I quoted it just as a try. It seems it only accepts quotes around the full path when there is a space in any part. So quoting only the parts with a space leads to the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.