I need to write a .bat script that will start excel on a specific file.

The hard part is that I don't know the exact path that excel is installed to.

Additionally, I need to start it with an option to make it readonly.

Here is some background to put the problem in context: Currently the .bat file looks like this:

"C:\My\Path\To\excel.exe" /r "S:\The\Path\To\File.xlsx" 

That file is on a shared drive. The user has a shortcut to to that file on their desktop.

When the user clicks on the short cut excel starts on File.xlsx.

But, when another user with a different path to excel does the same thing, the script just flashes the cmd window.

As an aside, I would also like to find a way to eliminate the cmd window from cluttering the screen while this is running.

This is related to this question: Allow multiple people to work with single readonly excel file

I tried making a short cut on the file and making the target:

start excel /r "S:\The\Path\To\File.xlsx" 

But if failed with this message: enter image description here

0

2 Answers

I can't test this at the moment, but I believe you can avoid the batch file. Simply create a shortcut with the following target:

Edit: Try the following for a batch file:

START excel.exe /r "S:\The\Path\To\File.xlsx" EXIT 

Also, I believe you could incorporate the registry key value for the Excel installation path by running the following batch command:

 reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe" 
0

I could not get the START to work in a shortcut because it requires a command line. I used the following and works great:

C:\Windows\System32\cmd.exe /c START excel.exe /r "Use the UNC path so you don't have to map drive here\File.xlsx"

When you put in cmd.exe it automatically hard codes the path C:\Windows\System32\cmd.exe
You can use %systemroot%\Systems32\cmd.exe..... to avoid hardcoding as much as possible.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy