Hi all,
How can I open ms Excel file in VB.net application.
Hi all,
How can I open ms Excel file in VB.net application.
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
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
You can refer to this links for some more information about it,
http://support.microsoft.com/kb/301982
http://support.microsoft.com/kb/302094
Don't use opaper's code. It's copied from another website and does NOT work.
Bookmarks