Determining how excel was started

G

Gilgamesh

I have an Auto_Open macro in a file in the XLStart directory that I want to
behave differently if Excel is launched just by running the .exe or by
double clicking on an .xls file.
There has been a suggestion of checking for the book1.xls file but because I
have files in the XLStart directory the book1.xls file does not get created
when excel is launched.

Is there any way of telling programatically how excel of started? In my old
unix days we could examine the parameter lines into the programe.

Thanks
 
G

Gilgamesh

Gilgamesh said:
I have an Auto_Open macro in a file in the XLStart directory that I want to
behave differently if Excel is launched just by running the .exe or by
double clicking on an .xls file.
There has been a suggestion of checking for the book1.xls file but because
I have files in the XLStart directory the book1.xls file does not get
created when excel is launched.

Is there any way of telling programatically how excel of started? In my
old unix days we could examine the parameter lines into the programe.

Thanks

I should have mentioned I'm using Excel 2003
 
H

Helmut Weber

Hi,

maybe this is a silly idea,
as I am just trying to get to grips with Excel.

If Excel was not started by double clicking on a file,
then only the Workbooks in the XLStart-folder are loaded.
To me it seems, they are loaded in alphabetical order.

So if your auto_open macro is in the last of the loaded
files, simply check whether the number of open workbooks
equals the number of Excel-files in XLStart.
If so, Excel was not started by double clicking on a file.

If you auto_open macro is not in the last file to be loaded,
then you could use application.ontime and wait some seconds,
til all files from XLStart are loaded. Like this:

Sub auto_open()
Application.OnTime Now + TimeValue("00:00:05"), "Checkbook"
End Sub

Sub checkbook()
If Workbooks.Count > 3 Then
MsgBox "Excel was started with file"
Else
MsgBox "Excel was started without file"
End If
End Sub

Not a very safe approach, though.

--
Greetings from Bavaria, Germany

Helmut Weber

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
N

NickHK

Gilgamesh,
There are ways to read Excel's Command line arguments. Not sure what it
would give you, but may include a filename if .xls file is clicked.
Can't find a link, but I have seen such.
Try a Google.

NickHK
 

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