Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 16-01-2009
Member
 
Join Date: Dec 2008
Posts: 12
Opening an Excel file in VB.NET

Hi all,

How can I open ms Excel file in VB.net application.
Reply With Quote
  #2  
Old 16-01-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Opening an Excel file in VB.NET

I hope this code will help you,

Code:
Dim excel As Microsoft.Office.Interop.Excel.Application

Dim wb As Microsoft.Office.Interop.Excel.Workbook

Try

excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Open("c:\\test.xls")
excel.Visible = True
wb.Activate()

Catch ex As COMException
MessageBox.Show("Error accessing Excel: " + ex.ToString())

Catch ex As Exception
MessageBox.Show("Error: " + ex.ToString())

End Try
Reply With Quote
  #3  
Old 16-01-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Opening an Excel file in VB.NET

I am not sure about it but you can try with this code.

Code:
Dim myExcel As Excel.ApplicationClass
Dim myWrkBk As Excel.Workbook()
Dim xcFileInfo As IO.FileInfo
Dim xcFileDialog As New OpenFileDialog()

xcFileDialog.Filter = "Excel Spreadsheet Files!
|*.xls"
xcFileDialog.Title = "Select estimate in excel
spreadsheet file!"
If xcFileDialog.ShowDialog = DialogResult.OK Then
xcFileInfo = New IO.FileInfo
(xcFileDialog.FileName)
myExcel = CreateObject("Excel.Application")
End If
Reply With Quote
  #4  
Old 16-01-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Opening an Excel file in VB.NET

You can refer to this links for some more information about it,

http://support.microsoft.com/kb/301982
http://support.microsoft.com/kb/302094
Reply With Quote
  #5  
Old 26-01-2009
Member
 
Join Date: Jan 2009
Posts: 1
Re: Opening an Excel file in VB.NET

Don't use opaper's code. It's copied from another website and does NOT work.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Opening an Excel file in VB.NET"
Thread Thread Starter Forum Replies Last Post
Getting error when opening excel file using a VB script Madri Software Development 4 18-07-2012 06:27 PM
Getting Error while opening Microsoft Excel 2000 file in Excel 2003 AbiaA MS Office Support 6 17-02-2012 01:18 PM
Opening file type .tsv with Excel Damned 2 Windows Software 5 12-01-2012 11:12 PM
Opening WK1 File in Microsoft Excel 2007 $horizon$ Windows Software 3 11-01-2012 06:07 PM
Problem opening Excel file with VBA code Lord Software Development 3 19-10-2009 09:50 AM


All times are GMT +5.5. The time now is 09:08 PM.