Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a specific excel file with a batch script and command line arguments?

I designed an excel spreadsheet that takes data from a server using an RTD feed and processes it. I want the excel file to open automatically during the computers startup. The way that I have decided to go about doing this is to write a batch script that opens the excel file and to then put that batch script in the computers startup folder.

The problem I am running into relates to the batch script. The RTD feed does not work if I use the default shortcut for excel. Instead I have to use a shortcut that has the following target line:

 "C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" /a "CompanyExcelAddin.CompanyFunctions"

I am able to open the file using this command line

start `"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" "C:\...\filename.xlsm"`

but I am not able to open a file using the following bash command

start "C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" /a "CompanyExcelAddin.CompanyFunctions" "C:\...\filename.xlsm"

If I open it using the first bash script the RTD feed doesn't work. If I try to run the second script the bash script doesn't run.

How do I write a bash script that takes command line arguments for the startup program?

like image 399
alluppercase Avatar asked Aug 01 '17 16:08

alluppercase


1 Answers

@echo off
set params=%*
start excel "MyWorkbook.xlsm" /e/%params%

Let's suppose you named it "MyBatch.bat", then you call it like this:

MyBatch.bat Hello/World1

Use space " " to separate parameters. Use slash "/" instead of space for parameters with spaces.

In case you do not like the string I believe you can also do this (in a *.bat file):
start excel "MyWorkbook.xlsm" /e/%param1%/%param2%/%param3%.....

In case you need to open several Excel instances:

@echo off
set params=%*
for %%C in (%params%) do (
    start excel "MyWorkbook.xlsm" /e/%%C
)
like image 72
Sergio Muriel Avatar answered Oct 05 '22 23:10

Sergio Muriel