CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Managed C++ and C++/CLI
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Managed C++ and C++/CLI Discuss Managed C++ and .NET-specific questions related to C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old July 19th, 2005, 06:00 PM
    chinniwhites chinniwhites is offline
    Member
     
    Join Date: Jun 2005
    Posts: 42
    chinniwhites is an unknown quantity at this point (<10)
    How to use OLE automation to open any version of Excel?

    I have written a program that uses ole to open Excel 2003. I believe this is dependent on the microsoft.office.interop.excel.dll (version 11). How could I write my program to open excel regardless of version and/or dll?
    Reply With Quote
      #2    
    Old July 20th, 2005, 07:57 AM
    Tom Frohman's Avatar
    Tom Frohman Tom Frohman is offline
    Member +
     
    Join Date: Apr 2002
    Location: Michigan, USA
    Posts: 836
    Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)
    Re: How to use OLE automation to open any version of Excel?

    A couple of suggestions:

    see
    http://www.codeguru.com/forum/showthread.php?t=337068

    1) rewrite the open function so it has a minimum number of arguments.
    2) test for version of excel and use the version of open for that version
    __________________
    Verere testudinem! (Fear the turtle)

    Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy. -Albert Einstein

    Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. -Cicero
    Reply With Quote
      #3    
    Old July 20th, 2005, 10:23 AM
    chinniwhites chinniwhites is offline
    Member
     
    Join Date: Jun 2005
    Posts: 42
    chinniwhites is an unknown quantity at this point (<10)
    Re: How to use OLE automation to open any version of Excel?

    I looked at the example and have a few questions. First, do i have to still use the microsoft.office.interop.excel namespace at the top of my code? If not, how will the program know how to intepret the application.open, saveas, and other commands link to the microsoft.office.interop.excel.dll? If i do use it, isnt dependent of the version of the dll (2003 being version 11)?
    Reply With Quote
      #4    
    Old July 20th, 2005, 10:56 AM
    chinniwhites chinniwhites is offline
    Member
     
    Join Date: Jun 2005
    Posts: 42
    chinniwhites is an unknown quantity at this point (<10)
    Re: How to use OLE automation to open any version of Excel?

    Also, how would you test for the version of the Office application that you are using? How would I open excel 2000 with the excel 2003 dll or does it not matter?
    Reply With Quote
      #5    
    Old July 20th, 2005, 01:04 PM
    Tom Frohman's Avatar
    Tom Frohman Tom Frohman is offline
    Member +
     
    Join Date: Apr 2002
    Location: Michigan, USA
    Posts: 836
    Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)
    Re: How to use OLE automation to open any version of Excel?

    Quote:
    Originally Posted by chinniwhites
    Also, how would you test for the version of the Office application that you are using? How would I open excel 2000 with the excel 2003 dll or does it not matter?
    Well, the way I would do it was to rewrite the prototypes of the functions to use the minimum number of arguments. That way 1 version will work for all versions of office.

    The test for version suggestion didn't come from me.
    However, I've seen the suggestion several times in the past.

    A couple of the ones I remembered
    http://www.codeguru.com/forum/showth...fice+namespace
    http://www.codeguru.com/forum/showth...office+version
    __________________
    Verere testudinem! (Fear the turtle)

    Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy. -Albert Einstein

    Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. -Cicero
    Reply With Quote
      #6    
    Old July 20th, 2005, 03:32 PM
    chinniwhites chinniwhites is offline
    Member
     
    Join Date: Jun 2005
    Posts: 42
    chinniwhites is an unknown quantity at this point (<10)
    Re: How to use OLE automation to open any version of Excel?

    Ok. How do I rewrite the Open and SaveAs for the Microsoft Office Library 11.0 so I can open and saveas using any version of excel?
    Reply With Quote
      #7    
    Old July 20th, 2005, 04:32 PM
    Tom Frohman's Avatar
    Tom Frohman Tom Frohman is offline
    Member +
     
    Join Date: Apr 2002
    Location: Michigan, USA
    Posts: 836
    Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)Tom Frohman  is a jewel in the rough (300+)
    Re: How to use OLE automation to open any version of Excel?

    I did this in the example sited above
    http://www.codeguru.com/forum/showthread.php?t=337068

    Here I go to the Class View and add a new class from a type library.
    Then I overload the generated SaveAs method with the version in the example.
    It will be in a different file than the one shown in the example because I did that with Visual C++ 6.0 and Excel 2000.
    __________________
    Verere testudinem! (Fear the turtle)

    Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy. -Albert Einstein

    Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. -Cicero
    Reply With Quote
      #8    
    Old July 20th, 2005, 04:37 PM
    chinniwhites chinniwhites is offline
    Member
     
    Join Date: Jun 2005
    Posts: 42
    chinniwhites is an unknown quantity at this point (<10)
    Re: How to use OLE automation to open any version of Excel?

    Would the code be the same?
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Managed C++ and C++/CLI


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 06:31 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009