Results 1 to 5 of 5

Thread: Opening an Excel file in VB.NET

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

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    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

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    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

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

Similar Threads

  1. Getting error when opening excel file using a VB script
    By Madri in forum Software Development
    Replies: 4
    Last Post: 18-07-2012, 06:27 PM
  2. Replies: 6
    Last Post: 17-02-2012, 01:18 PM
  3. Opening file type .tsv with Excel
    By Damned 2 in forum Windows Software
    Replies: 5
    Last Post: 12-01-2012, 11:12 PM
  4. Opening WK1 File in Microsoft Excel 2007
    By $horizon$ in forum Windows Software
    Replies: 3
    Last Post: 11-01-2012, 06:07 PM
  5. Problem opening Excel file with VBA code
    By Lord in forum Software Development
    Replies: 3
    Last Post: 19-10-2009, 09:50 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,039,878.40625 seconds with 17 queries