Home All Groups Group Topic Archive Search About

problem opening Excel file with Shell

Author
30 Apr 2006 4:39 PM
PJ6
This little snippet works for .txt files, but for any .xls file I get a file
not found error, even though the file is really there.

Yes, I checked to see if the path is correct, and yes, I have Excel
installed.

Any ideas what's going on? If I can't use Shell to get Excel to open a file,
what do I use?

TIA,
Paul

Public Overrides Sub Edit()
    Try
        If Not String.IsNullOrEmpty(FileName) Then Shell(FileName,
AppWinStyle.NormalFocus)
    Catch ex As Exception
        Dim msg As String = "Error attempting to edit " & Me.FileName & ":"
& vbCrLf & ex.Message
        MsgBox(msg, MsgBoxStyle.Exclamation, "function data editor")
    End Try
End Sub

Author
30 Apr 2006 6:02 PM
Cor Ligthert [MVP]
PJ6,

Use process start instead of shell, much easier to use.
\\\
Dim p As New System.Diagnostics.ProcessStartInfo()
p.WindowStyle = ProcessWindowStyle.Hidden
p.FileName = "C:\filename.xls"
p.UseShellExecute = True
System.Diagnostics.Process.Start(p)
///
Cor

Show quoteHide quote
"PJ6" <nob***@nowhere.net> schreef in bericht
news:%238K$2SHbGHA.3408@TK2MSFTNGP04.phx.gbl...
> This little snippet works for .txt files, but for any .xls file I get a
> file not found error, even though the file is really there.
>
> Yes, I checked to see if the path is correct, and yes, I have Excel
> installed.
>
> Any ideas what's going on? If I can't use Shell to get Excel to open a
> file, what do I use?
>
> TIA,
> Paul
>
> Public Overrides Sub Edit()
>    Try
>        If Not String.IsNullOrEmpty(FileName) Then Shell(FileName,
> AppWinStyle.NormalFocus)
>    Catch ex As Exception
>        Dim msg As String = "Error attempting to edit " & Me.FileName & ":"
> & vbCrLf & ex.Message
>        MsgBox(msg, MsgBoxStyle.Exclamation, "function data editor")
>    End Try
> End Sub
>
Author
1 May 2006 1:16 AM
PJ6
Thanks, thank worked.

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23wYXJAIbGHA.3408@TK2MSFTNGP04.phx.gbl...
> PJ6,
>
> Use process start instead of shell, much easier to use.
> \\\
> Dim p As New System.Diagnostics.ProcessStartInfo()
> p.WindowStyle = ProcessWindowStyle.Hidden
> p.FileName = "C:\filename.xls"
> p.UseShellExecute = True
> System.Diagnostics.Process.Start(p)
> ///
> Cor
>
> "PJ6" <nob***@nowhere.net> schreef in bericht
> news:%238K$2SHbGHA.3408@TK2MSFTNGP04.phx.gbl...
>> This little snippet works for .txt files, but for any .xls file I get a
>> file not found error, even though the file is really there.
>>
>> Yes, I checked to see if the path is correct, and yes, I have Excel
>> installed.
>>
>> Any ideas what's going on? If I can't use Shell to get Excel to open a
>> file, what do I use?
>>
>> TIA,
>> Paul
>>
>> Public Overrides Sub Edit()
>>    Try
>>        If Not String.IsNullOrEmpty(FileName) Then Shell(FileName,
>> AppWinStyle.NormalFocus)
>>    Catch ex As Exception
>>        Dim msg As String = "Error attempting to edit " & Me.FileName &
>> ":" & vbCrLf & ex.Message
>>        MsgBox(msg, MsgBoxStyle.Exclamation, "function data editor")
>>    End Try
>> End Sub
>>
>
>