?
Solved

open excel applicaiton along with a file

Posted on 2005-03-08
12
Medium Priority
?
408 Views
Last Modified: 2010-05-19

can someone provide a better way of opening this file.. I want to do this only through shell command

file = "c:\Program Files\Boast98\" & Form1.Combo9.Text & "\InputFile.xls"
oshell = Shell("D:\Program Files\Microsoft Office\Office10\Excel.exe " & file, vbNormalFocus)

Thank you.
0
Comment
Question by:Aiysha
9 Comments
 
LVL 35

Expert Comment

by:mvidas
ID: 13491636
Hi Aiysha,

Looks good to me, if you want to stick with the shell command.  Only thing I can think of is that the Office directory is probably part of the path, so you could always just use
 oshell = Shell("excel.exe " & file, vbNormalFocus)

Matt
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13491986
How To Use ShellExecute to Launch Associated File (32-bit)
http://support.microsoft.com/default.aspx?scid=kb;en-us;170918
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 13495388
You could also use the FindExecutable API to find the location of Excel for you:


Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long


Private Sub Command1_Click()
file = "c:\Program Files\Boast98\" & Form1.Combo9.Text & "\InputFile.xls"
LaunchExcelFile file, vbNormalFocus
End Sub


Private Function LaunchExcelFile(xlFile As String, Optional WindowStyle As VbAppWinStyle = vbNormalFocus) As Double
Dim strEXE As String * 255, xlLocation As String, RetVal As Long
Call FindExecutable(xlFile, "", strEXE)
xlLocation = Left$(strEXE, InStr(strEXE, Chr$(0)) - 1)
Shell xlLocation & Space$(1) & xlFile, WindowStyle
End Function
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Aiysha
ID: 13496161
Thank you for all your responses.
mvidas, The shell method metioned above is only good to open files on C drive.. it fails to read files in other directories. Can someone please give me more tips on this.

Thank you.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13496203
Is your goal to open a specific xls file in Excel
or to open a specific version of Excel on the D drive?
0
 

Author Comment

by:Aiysha
ID: 13496258
To open specific file through shell method.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 1500 total points
ID: 13496415
If you want to use Shell (and not the preferred ShellExecute method) then vinnyd79 has the solution for you.

I would make only one small change, and that is to wrap the filename in double quotes.  If you pass in a long filename that contains spaces, the function will not work properly.

'using the function provided by vinnyd79
Private Sub Command1_Click()
    Dim sFile As String
    'Point to the file you want to open
    sFile = "E:\Program Files\Microsoft Office\Office10\Samples\samples.xls"
    'wrap the filename in double quotes
    LaunchExcelFile Chr(34) & sFile & Chr(34), vbNormalFocus
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13496479
Of course, if you were getting errors saying "c:\Program.xls could not be found.." try wrapping the filename in double quotes and passing it on to Shell as you did originally:

file = chr(34) & "c:\Program Files\Boast98\" & Form1.Combo9.Text & "\InputFile.xls" & chr(34)

oshell = Shell("D:\Program Files\Microsoft Office\Office10\Excel.exe " & file, vbNormalFocus)

0
 
LVL 32

Expert Comment

by:Erick37
ID: 13582830
Need more help on this question?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question