1

I have an application calls the below command:

C:\Users\212340141>"C:\Program Files\Microsoft Office\Office14\excel.exe" /e "C:
\My Programs\CPU Analysis\data\IOParse.xlsm" "-iodumplocation"C:\My Programs\CPU
Analysis\iodump\065901_iodump.txt""

When I run this command, it opens excel, passing in the C:\My Programs\CPU Analysis\iodump\065901_iodump.txt path as a parameter for the excel book to use in the macros it runs automatically. The macros run correctly and the file is modified correctly, but I get the following errors when I run the command:

First Error

Second Error

Third Error

Fourth Error

How can I get rid of the errors?

Answer

As mentioned in the accepted answer, excel was trying to open multiple files because of how I wrote the command. The way I solved this is I created a text file to hold the path I was trying to pass into the macro. The macro would open the text file and read the path to get the path it needed. This is much cleaner and easier than trying to get the path from the command line.

Luuklag
  • 3,897
  • 11
  • 38
  • 57
Tim Hutchison
  • 3,483
  • 9
  • 40
  • 76

1 Answers1

1

Description of the startup switches for Excel lists and describes the optional switches which can be used on starting Excel. /e is listed on this page written by Microsoft. But -iodumplocation is definitely not a command line switch for Excel.

Using double quotes within a double quoted string is always a mistake on command line and the result is unpredictable as depending on code of command line parser, see answer on Why double quotes should be always only at beginning and end of an argument string?

The command line used is obviously interpreted by Excel as

"C:\Program Files\Microsoft Office\Office14\excel.exe" /e "C:\My Programs\CPU Analysis\data\IOParse.xlsm" "-iodumplocation" C:\My Programs\CPU Analysis\iodump\065901_iodump.txt""

which results in

  1. /e ... starting without displaying the startup screen and without the creation of a new workbook.
  2. C:\My Programs\CPU Analysis\data\IOParse.xlsm ... opening this marco-enabled workbook file.
  3. -iodumplocation ... the failed attempt to open a file with name -iodumplocation.xlsx in current working directory.
  4. C:\My ... the failed attempt to open a file with name My.xlsx in root of drive C:.
  5. Programs\CPU ... the failed attempt to open a file with name CPU.xlsx in subdirectory Programs of current working directory.
  6. Analysis\iodump\065901_iodump.txt"" ... the failed attempt to open a file with invalid name 065901_iodump.txt"" in subdirectory Analysis\iodump of current working directory.

I can't suggest a correct command line as I don't know what -iodumplocation should be.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143