Reputation: 854
I have a batch file that essentially just checks the version of MSExcel and opens a different file based on that. However, I'm running into a strange problem where, after successfully running the batch file, Excel returns the error:
"The file could not be accessed. Try one of the following:" (Lists suggestions)
The strangest part, though, is that when I press OK, the file still opens properly! I really would love to get rid of this error for my users; what could I do to get rid of it?
Here is my code, in case anyone was wondering.
@echo off
echo %~dp0
if exist "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" GOTO L2010
if exist "C:\Program Files\Microsoft Office\Office12\EXCEL.EXE" GOTO L2007
if exist "C:\Program Files\Microsoft Office\Office11\EXCEL.EXE" GOTO L2003
echo "Excel not installed"
pause
GOTO End
:L2010
:L2007
Start excel.exe %~dp0 "resources\SQL_Report_Compiler.xlsm"
GOTO End
Pause
:L2003
Start excel.exe %~dp0 "resources\SQL_Report_Compiler.xls"
:End
Upvotes: 0
Views: 41
Reputation: 32170
Your code is passing two arguments, not one, so Excel thinks you're trying to open two documents.
For example, try running:
Start excel.exe Spreadsheet1.xlsx Spreadsheet2.xlsx
You'll open both spreadsheets. The space is what's throwing it.
You get an error on the first argument because you can't open a directory itself as a file.
The second argument probably works because Excel will naturally search the current directory somewhat.
Try:
Start excel.exe "%~dp0resources\SQL_Report_Compiler.xlsm"
And:
Start excel.exe "%~dp0resources\SQL_Report_Compiler.xls"
Upvotes: 1