Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open an Excel file using Shell 1

Status
Not open for further replies.

MrMajik

IS-IT--Management
Apr 2, 2002
267
Using a pull-down menu I am trying to get one of the menu items to open an Excel spreadsheet.
Why won't this work?


Dim myFile As Variant 'used to open the spreadsheet file

Private Sub mnuMySpreadsheet_Click()
myFile = Shell(App.Path & "\My Spreadsheet.xls", 1)
End Sub

Thank you.
 
You're going to need to use Excel to actually open the file. Excel takes a parameter of a file path to open

i.e.
Code:
Shell("C:\Program Files\Microsoft Office\Office12\EXCEL.EXE Book.xls")

Shell doesn't know what to do with just the .xls without an executable to render it

____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood

 
onpnt,

That did it. Thank you :)

Thank you,

MrMajik

There are 10 types of people in the world:
Those that understand binary and those that don't.
 
:)

I would also look into using cmd /c filename.xls. This way you wouldn't have to reply on using excel.exe. gmmastros had a reply awhile back on this. Then you just reply on the file associations of the machine the program is running on.
>> Call Shell("cmd /c C:\book1.xls")

Or create an instance of excel programmatically and then use everything it has to offer to control the resource.

____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood

 
ShellExecute API?

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long



 
I would go with vbSun's suggestion:

Code:
    Dim res As Long
    res = ShellExecute(hWnd, vbNullString, txtReportFile.Text, vbNullString, vbNullString, vbNormalFocus)
    If res = 31 Then
        MsgBox "This file is not associated with a program!", vbCritical, "File Association Error"
        Exit Sub
    End If

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top