10

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 batch script the RTD feed doesn't work. If I try to run the second script the batch script doesn't run.

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

2
  • Batch scripts and bash scripts are different animals, powershell even moreso. Please edit your 'question' by removing the non necessary tags and changing what is a broad/generic question to something more specific. As you currently have it, it looks like you are requesting a free solution using any method which is both rude and technically off topic. Commented Aug 1, 2017 at 16:34
  • Put an empty pair of quotes before any path components, like start "" "C:\Program Files (x86)\...\EXCEL.EXE" /a ..., because start often interprets the first quoted string as a window title... Commented Aug 1, 2017 at 17:47

3 Answers 3

12
@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
)
Sign up to request clarification or add additional context in comments.

2 Comments

How can I open a protected sheet/workbook from this same batch script ? Is it just a matter of passing another parameter or a whole different story ?
1

First, I'd recommend using a scheduled task over the startup folder (consistent behavior). Trigger on login, or however you need it, and execute powershell -ExecutionPolicy Bypass -NoProfile -File 'thing.ps1'. It looks like you may be passing the arguments out of order for the Excel exe.

$EXE = "${env:ProgramFiles(x86)}\Microsoft Office\root\Office16\EXCEL.EXE"
& $EXE 'C:\...\filename.xlsm' /a 'CompanyExcelAddin.CompanyFunctions'

Comments

0

I dont know what RTD is ? can yu please define acronyms at least once for everyones sake. We are not in the British Military, or a Monty Python skit. Easiest way from command prompt (CMD); start excel or start excel W:\mortgages\myfile.xls

Picaso not Pollock

You can also use a BATCH file with these commands, which also works best for TASK SCHEDULER, but I would always put net use command for the drive on a network since the TASK SCHED instance may not recognize them. Task scheduler is really problematic with black box responses (in code), but I have found using a batch file resolves most issues.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.