Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Determine If A File Was Specified When Starting Excel

Is there a property that I can read to find out if a file was specified to
open when starting Excel? In other words, if Excel was opened via the Start
menu (so the application opens, but no file is opened), or if Excel was
opened by double-clicking on an .xls file (so the application opens, then the
specified file opens).

The reason I would like to know is that I have created an .xls file, located
in my XLSTART folder, that provides some additional functionality not native
to Excel. When this file is not present, and I open Excel via the Start
menu, a blank worksheet is created. When the file is present, and I open
Excel via the Start menu, a blank worksheet is not created. I would like to
have the blank worksheet created when my file is present in the XLSTART
folder.

I know I can make this happen by placing the line
"Application.Workbooks.Add" in the "Workbook_Open" Application Event of the
file in XLSTART, but when Excel is opened by double-clicking on an .xls file,
a blank workbook is created as well, and I would prefer that not to happen.
If I could get an answer to my question, I would be able to add a workbook
only if Excel was opened without specifying a file. I cannot do this by
counting the number of open workbooks, because my file in XLSTART loads
before any other .xls file that may have been opened.

I hope I have described this clearly. If not, please let me know. Thanks
in advance for any help that may be forthcoming.

-Michael
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Determine If A File Was Specified When Starting Excel

On Jul 2, 3:48 pm, Michael H
wrote:
Is there a property that I can read to find out if a file was specified to
open when starting Excel? In other words, if Excel was opened via the Start
menu (so the application opens, but no file is opened), or if Excel was
opened by double-clicking on an .xls file (so the application opens, then the
specified file opens).

The reason I would like to know is that I have created an .xls file, located
in my XLSTART folder, that provides some additional functionality not native
to Excel. When this file is not present, and I open Excel via the Start
menu, a blank worksheet is created. When the file is present, and I open
Excel via the Start menu, a blank worksheet is not created. I would like to
have the blank worksheet created when my file is present in the XLSTART
folder.

I know I can make this happen by placing the line
"Application.Workbooks.Add" in the "Workbook_Open" Application Event of the
file in XLSTART, but when Excel is opened by double-clicking on an .xls file,
a blank workbook is created as well, and I would prefer that not to happen.
If I could get an answer to my question, I would be able to add a workbook
only if Excel was opened without specifying a file. I cannot do this by
counting the number of open workbooks, because my file in XLSTART loads
before any other .xls file that may have been opened.

I hope I have described this clearly. If not, please let me know. Thanks
in advance for any help that may be forthcoming.

-Michael


Hello Michael,

To control how Excel opens have look at this article, it may help
answer your question.

http://support.microsoft.com/kb/291288

Sincerely,
Leith Ross

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Determine If A File Was Specified When Starting Excel

Michael,
You can read the Command line that was sent to Excel:
http://www.dailydoseofexcel.com/arch...uments-in-vba/

NickHK

"Michael H" wrote in message
...
Is there a property that I can read to find out if a file was specified to
open when starting Excel? In other words, if Excel was opened via the

Start
menu (so the application opens, but no file is opened), or if Excel was
opened by double-clicking on an .xls file (so the application opens, then

the
specified file opens).

The reason I would like to know is that I have created an .xls file,

located
in my XLSTART folder, that provides some additional functionality not

native
to Excel. When this file is not present, and I open Excel via the Start
menu, a blank worksheet is created. When the file is present, and I open
Excel via the Start menu, a blank worksheet is not created. I would like

to
have the blank worksheet created when my file is present in the XLSTART
folder.

I know I can make this happen by placing the line
"Application.Workbooks.Add" in the "Workbook_Open" Application Event of

the
file in XLSTART, but when Excel is opened by double-clicking on an .xls

file,
a blank workbook is created as well, and I would prefer that not to

happen.
If I could get an answer to my question, I would be able to add a workbook
only if Excel was opened without specifying a file. I cannot do this by
counting the number of open workbooks, because my file in XLSTART loads
before any other .xls file that may have been opened.

I hope I have described this clearly. If not, please let me know. Thanks
in advance for any help that may be forthcoming.

-Michael



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Determine If A File Was Specified When Starting Excel

Leith and NickHK,

Thanks very much for your responses.

Based on the code from the link provided by NickHK, I created the following
function:

Declare Function GetCommandLineA Lib "Kernel32" () As String

Public Function FileParameter() As Boolean

Dim strCmdLine As String

strCmdLine = GetCommandLineA
strCmdLine = Mid(strCmdLine, 1, 255)

If InStr(1, strCmdLine, "/e") < 0 Then
FileParameter = True
Else
FileParameter = False
End If

End Function


This worked, but sometimes when opening a file directly in Excel, it would
crash with a "Microsoft Excel has encountered a problem and needs to close"
error. When I put a stop in the code so as to step through it, the crash
does not occur. I am unable to find the cause of this issue so far.

After a bit more searching for info on "Command Line", I found the following:
http://groups.google.co.uk/group/mic...ca75a8220396ce


I managed to use the code in Post# 6 to accomplish what I needed:

Private Declare Function GetCommandLine Lib "kernel32" Alias
"GetCommandLineA" () As Long

Select Case GetCommandLine()
Case 1385360
'No file specified. Add new workbook.
Application.Workbooks.Add
Case 1385376
'File specified. Do nothing
End Select

I need to do more testing, because I'm not sure yet if there are any other
possible values for the results of GetCommandLine. However, it works well so
far.

Once again, thanks to both of you for the responses, which helped to put me
on the right track.

-Michael
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine Excel file version with no file extension. tjlumpkin Excel Discussion (Misc queries) 2 July 23rd 09 06:59 AM
Starting an Excel 2003 file from Excel 2007 ReneI Setting up and Configuration of Excel 3 August 30th 08 08:16 AM
Starting Excel from a file beel Excel Programming 2 April 11th 06 01:41 AM
starting .bat file from excel VBA Mark Excel Programming 2 December 29th 05 06:52 PM
Starting a userform upon starting the file Fritznel Excel Programming 1 July 28th 03 05:37 AM


All times are GMT +1. The time now is 04:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"