1

I am trying to run a Shell script from Excel using VBA. The Terminal prompt I to run the script is cat "prompt.csv" | sh runScript.sh "WSO". The following code attempts to run that line, but I run into an

Error 53: File Not Found

Any help is much appreciated!

Sub Run_Jar()
    ChDir ActiveWorkbook.Path
    Shell "cat 'prompt.csv' | sh runScript.sh 'WSO'"
End Sub

The possible duplicate is for Office 2011, but I am using Office 2016. I need parameters, so Shell() does not work, MacScript() is an outdated command, and I cannot find libc.dylib on my machine.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
taurus
  • 470
  • 7
  • 22
  • 1
    What environment are you running this in? – Sam Jul 08 '19 at 20:52
  • @Sam I'm not sure, how can I check? – taurus Jul 08 '19 at 20:55
  • 13
    @taurus Is there a bitten apple on the outside of the case? – GSerg Jul 08 '19 at 20:59
  • Yes, there is.. – taurus Jul 08 '19 at 21:10
  • Possible duplicate of [VBA Shell function in Office 2011 for Mac](https://stackoverflow.com/q/6136798/11683) – GSerg Jul 08 '19 at 21:12
  • @GSerg None of those solutions worked. – taurus Jul 11 '19 at 22:38
  • This is excel for mac? If so please add the necessary tag to your post – Tarun Lalwani Jul 12 '19 at 04:08
  • Are both files (`prompt.csv` and `runScript.sh`) in the same folder as your workbook? Does this command run `cat 'prompt.csv' | sh runScript.sh 'WSO'` when you run it in a terminal in the path of your workbook? – Pᴇʜ Jul 12 '19 at 07:52
  • Yes, the files are in the same folder. That prompt does work correctly from terminal. I found a solution using AppleScript, but it involves copying a script to Excel's script folder. I would like to distribute this workbook, so that is not an ideal solution. – taurus Jul 12 '19 at 13:17
  • 1
    I've never worked with Apple but I assume the syntax is similar to Linux's bash: have you tried: 1) to add `./` in front of the file name (e.g. `./prompt.csv` and `./runScript.sh`)? When calling a shell from code, it doesn't have the same context than calling it via the UI console.; 2) if that doesn't work, have you tried to add full path of the files? (in Linux would be `/folder1/folder2/folder3/prompt.csv`)? Still the same principle of the context which is missing in a runtime shell and is not in a UI shell... – Matteo NNZ Jul 12 '19 at 19:22
  • You need to ChDrive first to make sure the drive is active. If its still error, after chdir try print the current directory and append the current directory to the file name. – Donnie Jul 18 '19 at 04:34

0 Answers0