dcsimg
Results 1 to 6 of 6

Thread: error while opening the excel file from vb.net

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2011
    Posts
    52

    error while opening the excel file from vb.net

    hi every one

    i am getting error while opening an excel file from a vb.net application

    Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D


    i am working with visual Studio 2010 and ms office 2007 in windows 10 operating system for a visual basic.net application

    this is my code


    Dim ofd As New OpenFileDialog("Select Excel spreadsheet to link", Nothing, "xls; xlsx", "ExcelFileToLink", OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles)
    Dim dr As System.Windows.Forms.DialogResult = ofd.ShowDialog()


    If dr <> System.Windows.Forms.DialogResult.OK Then
    Return
    End If

    ed.WriteMessage(vbLf & "File selected was ""{0}"".", ofd.Filename)


    Dim fpath As String = Path.GetDirectoryName(ofd.Filename)

    Dim xlApp As New Excel.Application

    Dim obook As Excel.Workbook = xlApp.Workbooks.Open(ofd.Filename)

    the above line i am getting the above error.
    i did not figure out even after spent so much time that what went wrong?
    any one please give me a solution what went wrong

    thanks in advances
    gvg

  2. #2
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    721

    Re: error while opening the excel file from vb.net

    Quote Originally Posted by gvgbabu View Post
    hi every one

    i am getting error while opening an excel file from a vb.net application

    Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D


    i am working with visual Studio 2010 and ms office 2007 in windows 10 operating system for a visual basic.net application

    this is my code


    Dim ofd As New OpenFileDialog("Select Excel spreadsheet to link", Nothing, "xls; xlsx", "ExcelFileToLink", OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles)
    Dim dr As System.Windows.Forms.DialogResult = ofd.ShowDialog()


    If dr <> System.Windows.Forms.DialogResult.OK Then
    Return
    End If

    ed.WriteMessage(vbLf & "File selected was ""{0}"".", ofd.Filename)


    Dim fpath As String = Path.GetDirectoryName(ofd.Filename)

    Dim xlApp As New Excel.Application

    Dim obook As Excel.Workbook = xlApp.Workbooks.Open(ofd.Filename)

    the above line i am getting the above error.
    i did not figure out even after spent so much time that what went wrong?
    any one please give me a solution what went wrong

    thanks in advances
    gvg
    Full code? And where is the OpenFileDialog object comming from? The ones in Microsoft.Win32 and System.Windows.Forms don't appear to have properties/fields your code is referencing.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2011
    Posts
    52

    Re: error while opening the excel file from vb.net

    thanks for your reply Peter Swinkels ,

    this is my code with a windows form and 3 buttons on the form


    Imports Microsoft.Office.Interop
    Imports Excel = Microsoft.Office.Interop.Excel

    Public Class Form1
    '~~> Define your Excel Objects
    i am getting the error the below line
    Dim xlApp As New Excel.Application
    Dim xlWorkBook As Excel.Workbook

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '~~> Add a New Workbook
    xlWorkBook = xlApp.Workbooks.Add

    '~~> Display Excel
    xlApp.Visible = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    '~~> Opens an existing Workbook. Change path and filename as applicable
    xlWorkBook = xlApp.Workbooks.Open("C:\Users\bhavajna\Desktop\New folder (3)\input for Aq.xls")

    '~~> Display Excel
    xlApp.Visible = True
    End Sub

    the error is

    Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).


    please help me how to solve this problem

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2011
    Posts
    52

    Re: error while opening the excel file from vb.net

    i am using visual studio 2010 ms office 2007 in windows 10
    is it compatability issue or anything else?

    please help me how to solve this problem

    gvg
    Last edited by gvgbabu; Jul 28th, 2019 at 07:20 AM.

  5. #5
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    721

    Re: error while opening the excel file from vb.net

    Quote Originally Posted by gvgbabu View Post
    i am using visual studio 2010 ms office 2007 in windows 10
    is it compatability issue or anything else?

    please help me how to solve this problem

    gvg
    You didn't answer my questions. Could you post the entire project?

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2011
    Posts
    52

    Resolved Re: error while opening the excel file from vb.net

    i solved my self using the below

    tools-->Add sharepoint connection

    it solved my problem

    thanks you swinkels for you support

    gvg
    Last edited by gvgbabu; Jul 28th, 2019 at 08:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width