problem opening Excel file with Shell

P

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
 
C

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
 
P

PJ6

Thanks, thank worked.

Cor Ligthert said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top