954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Open Excel File

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

ViRiPuFF
Light Poster
32 posts since Jun 2007
Reputation Points: 16
Solved Threads: 0
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

ViRiPuFF
Light Poster
32 posts since Jun 2007
Reputation Points: 16
Solved Threads: 0
 

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
mazel
Newbie Poster
3 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 
bruce2424
Newbie Poster
23 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You