problem opening Excel file with Shell

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PJ6

    #1

    problem opening Excel file with Shell

    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.IsNullOr Empty(FileName) Then Shell(FileName,
    AppWinStyle.Nor malFocus)
    Catch ex As Exception
    Dim msg As String = "Error attempting to edit " & Me.FileName & ":"
    & vbCrLf & ex.Message
    MsgBox(msg, MsgBoxStyle.Exc lamation, "function data editor")
    End Try
    End Sub


  • Cor Ligthert [MVP]

    #2
    Re: problem opening Excel file with Shell

    PJ6,

    Use process start instead of shell, much easier to use.
    \\\
    Dim p As New System.Diagnost ics.ProcessStar tInfo()
    p.WindowStyle = ProcessWindowSt yle.Hidden
    p.FileName = "C:\filename.xl s"
    p.UseShellExecu te = True
    System.Diagnost ics.Process.Sta rt(p)
    ///
    Cor

    "PJ6" <nobody@nowhere .net> schreef in bericht
    news:%238K$2SHb GHA.3408@TK2MSF TNGP04.phx.gbl. ..[color=blue]
    > 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.IsNullOr Empty(FileName) Then Shell(FileName,
    > AppWinStyle.Nor malFocus)
    > Catch ex As Exception
    > Dim msg As String = "Error attempting to edit " & Me.FileName & ":"
    > & vbCrLf & ex.Message
    > MsgBox(msg, MsgBoxStyle.Exc lamation, "function data editor")
    > End Try
    > End Sub
    >[/color]


    Comment

    • PJ6

      #3
      Re: problem opening Excel file with Shell

      Thanks, thank worked.

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
      news:%23wYXJAIb GHA.3408@TK2MSF TNGP04.phx.gbl. ..[color=blue]
      > PJ6,
      >
      > Use process start instead of shell, much easier to use.
      > \\\
      > Dim p As New System.Diagnost ics.ProcessStar tInfo()
      > p.WindowStyle = ProcessWindowSt yle.Hidden
      > p.FileName = "C:\filename.xl s"
      > p.UseShellExecu te = True
      > System.Diagnost ics.Process.Sta rt(p)
      > ///
      > Cor
      >
      > "PJ6" <nobody@nowhere .net> schreef in bericht
      > news:%238K$2SHb GHA.3408@TK2MSF TNGP04.phx.gbl. ..[color=green]
      >> 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.IsNullOr Empty(FileName) Then Shell(FileName,
      >> AppWinStyle.Nor malFocus)
      >> Catch ex As Exception
      >> Dim msg As String = "Error attempting to edit " & Me.FileName &
      >> ":" & vbCrLf & ex.Message
      >> MsgBox(msg, MsgBoxStyle.Exc lamation, "function data editor")
      >> End Try
      >> End Sub
      >>[/color]
      >
      >[/color]


      Comment

      Working...