?
Solved

open excel applicaiton along with a file

Posted on 2005-03-08
12
Medium Priority
?
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 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
Independent Software Vendors: 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!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

765 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