CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2013
    Posts
    28

    Thumbs up Copying the data from one workbook to another Work book, cauing the error-COM class

    Hi all,

    I need to copy all the sheets from Workbook1 to another Workbook2 one by one.
    I wrote the code, and i got the error at 1st line :-(.

    How to resolve this error?
    The error is -
    Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).


    I have written the following code...
    Code:
    Imports Excel = Microsoft.Office.Interop.Excel
    Imports Microsoft.Office.Interop.Excel
    
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
    'Open a file into the first book.
            Dim excelWorkbook0 As Workbook = New Workbook("D:\PSR Conversion to VB.net\Book1.xlsx")
    
            'Create another Workbook.
            Dim excelWorkbook1 As Workbook = New Workbook()
    
            'Copy the first sheet of the first book into second book.
            excelWorkbook1.Worksheets(0).Copy(excelWorkbook0.Worksheets(0))
    
            'Save the file.
            excelWorkbook1.SaveAs("C:\FinalBook.xls")
    end sub
    Also if anyone knows to do it any other way, i will be glad to know it.

    Thanks in advance

    Regards
    Soni
    Last edited by SeemsP; March 9th, 2015 at 06:43 AM.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Copying the data from one workbook to another Work book, cauing the error-COM cla

    Have you set the correct references to the correct Excel version?

  3. #3
    Join Date
    Jan 2013
    Posts
    28

    Re: Copying the data from one workbook to another Work book, cauing the error-COM cla

    Quote Originally Posted by HanneSThEGreaT View Post
    Have you set the correct references to the correct Excel version?
    Hi HannesTheGreat,

    I followed the following steps:
    1. On the top -->Project --> Add References --> from COM section ->Microsoft Excel 14.0 object Library.

    Humm

    and i am using MS Excel 2010.

    Can guide me where i went wrong? Please...

    Regards
    Soni

  4. #4
    Join Date
    Jan 2013
    Posts
    28

    Re: Copying the data from one workbook to another Work book, cauing the error-COM cla

    Hi Friends,

    Can any one please help me out with this...

    I need to copy one work sheet without loosing the formatting, to another Workbook..

    If you have some useful links , please do provide me.... i need it , its necessary

    Regards
    Prity

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured