Hi

I'm using MS Visual Basic 2005 Express Edition and need to open an Excel File. I'm using the following code

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xlTemp As Excel.Application
        xlTemp = New Excel.Application
        xlTemp.Workbooks.Open("C:\Documents and Settings\TAP\Desktop\Post\Test.xls")
    End Sub
End Class

I get no errors but nothing happens when I click the button.

Thanks

Comments
welcome to daniweb

>I get no errors but nothing happens when I click the button.
I'm guessing that something does happen, but since you don't do anything that produces a noticeable effect, it seems like nothing is happening.

This is probably not the ideal solution but maybe you could do...

Private Sub CallProcess(ByVal path As String)
        Dim p As New System.Diagnostics.Process
        p.StartInfo.FileName = path
        p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
        p.Start()

        'Wait until the process passes back an exit code 
        p.WaitForExit()

        'Free resources associated with this process
        p.Close()
    End Sub
CallProcess("C:\crap.xls")

Although the methods for excel files which you are already using are probably a better option.

Yes Indeed it did Open the Excel File in Read Only Mode. Is there a way I could Open the File in Normal View

ViRi

i think you forgot to make the application visible.

Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xlTemp As Excel.Application
        xlTemp = New Excel.Application
        xlTemp.Workbooks.Open("C:\Documents and Settings\TAP\Desktop\Post\Test.xls")
        xlTemp.Visible = True    '<---- Add this part
    End Sub
End Class
This article has been dead for over six months. Start a new discussion instead.