rohrl77 rohrl77 - 2 months ago 12
Bash Question

Execute shell is not opening up file provided as string

I am trying to solve an error in code written by someone else. The shell function running in an MS Excel VBA environment is as follows:

Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret&

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function


The
cmdline$
input is: "excel.exe W:\L\BDTP\Products\Mandate FS\OfferToolUpdate.xlsm"

When I run the code it opens another excel instance and attempts to open a file under "W:\L\BDTP\Products\Mandate.xlsx"... after two more error messages it tells me that it can also not find "FS\OfferToolUpdate.xlsm"

Clearly this error is produced some how due to the space in the naming convention of the Folder the file resides in.

How can I open the file without changing the folder name?

Answer

I believe you used example as shown at: https://support.microsoft.com/en-us/kb/129796 ...

Just update execution line to wrap out the file:

ExecCmd "excel.exe ""U:\ADMINISTRATION\Expenses\Some File.xlsx"""