Is it possible to pass arguments to excel file ? (from command line)

T

tal

Hello there.

I have an excel workbook that on open contacts a database.
I would like to make it optional with an argument i'll
pass when opening the file. Is it possible?
 
H

Harlan Grove

I have an excel workbook that on open contacts a database.
I would like to make it optional with an argument i'll
pass when opening the file. Is it possible?

There may be a more elegant way using Windows API calls, but the crude way would
be to use a batch file to load the command line tail into an environment
variable that an Excel workbook could read. For example, use the following batch
file to store the command line tail in the environment variable cmdln and launch
Excel.


@REM begin startxl.bat
@echo off

set op=%PROMPT%
set PROMPT=$z

set xlfn=%1
shift

set cmdln=%1

:loop
shift
if "%1" == "" goto cont
set cmdln=%cmdln% %1
goto loop

:cont
start excel %xlfn%

set xlfn=
set cmdln=

set PROMPT=%op%
set op=

exit
@REM end startxl.bat


Then use a Workbook_Open event handler to fetch the command line tail.


Private Sub Workbook_Open()

MsgBox Prompt:=Environ("cmdln"), _
Buttons:=vbOKOnly, _
Title:="Command line tail"

End Sub


Run the batch file using a PIF file that starts off in a minimized window, and
it'll be difficult to tell that Excel isn't loading as it would by directly
running excel.exe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top