Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Excel Automation Using C++ #import

Excel Automation Using C++ #import

Scheduled Pinned Locked Moved C / C++ / MFC
c++testingtoolshelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Doug Knudson
    wrote on last edited by
    #1

    Hi All, Very new to Excel Automation but have done a lot with Word Automation. Using VC++ V6 and Excel 2000. I simply need to get a range object that corresponds to the current user selection. This is what I thought would work: Excel::IRangePtr spRange = msp_excel->GetSelection(); There is an active sheet and a selection of cells but spRange (the smart pointer) is always returned as null??? I am also puzzled by the fact that there doesn't seem to be a Selection object, per se, something that could be returned and worked with via ISelectionPtr or the like??? Any help greatly appreciated! Thanks, Doug

    Doug Knudson

    R 1 Reply Last reply
    0
    • D Doug Knudson

      Hi All, Very new to Excel Automation but have done a lot with Word Automation. Using VC++ V6 and Excel 2000. I simply need to get a range object that corresponds to the current user selection. This is what I thought would work: Excel::IRangePtr spRange = msp_excel->GetSelection(); There is an active sheet and a selection of cells but spRange (the smart pointer) is always returned as null??? I am also puzzled by the fact that there doesn't seem to be a Selection object, per se, something that could be returned and worked with via ISelectionPtr or the like??? Any help greatly appreciated! Thanks, Doug

      Doug Knudson

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      Make sure you have an interface pointer to the sheet you think you're using. Try and do something else such as selecting "A1" and write something to it. The application object contains a collection of workbooks that contains a collection of worksheets and so on. You need to get the correct sheet. Is msp_excel really an interface opinter to a worksheet? The name that implies a opinter to the application object makes me wonder...;) It's been a while since I automated Excel, but I remember a lot of calls to functions such as GetActiveWorkbook(), GetActiveSheet(). A good thing is to explicitly make the application visible to the user; you might have a second instance of Excel running. -- Roger


      "It's supposed to be hard, otherwise anybody could do it!" - selfquote

      "No one remembers a coward!" - Jan Elfström 1998
      "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above

      D 1 Reply Last reply
      0
      • R Roger Stoltz

        Make sure you have an interface pointer to the sheet you think you're using. Try and do something else such as selecting "A1" and write something to it. The application object contains a collection of workbooks that contains a collection of worksheets and so on. You need to get the correct sheet. Is msp_excel really an interface opinter to a worksheet? The name that implies a opinter to the application object makes me wonder...;) It's been a while since I automated Excel, but I remember a lot of calls to functions such as GetActiveWorkbook(), GetActiveSheet(). A good thing is to explicitly make the application visible to the user; you might have a second instance of Excel running. -- Roger


        "It's supposed to be hard, otherwise anybody could do it!" - selfquote

        "No one remembers a coward!" - Jan Elfström 1998
        "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above

        D Offline
        D Offline
        Doug Knudson
        wrote on last edited by
        #3

        Hi Roger, Thanks very much for the response. In answer to your questions... msp_excel is a pointer to the "Application Object" defined as _ApplicationPtr and yes, though strange and at least in the wrapper files (.tlh and .tli) generated by the #import, the Selection is associated with the Application Object, not the sheet. Another strange thing to me is that a Selection does not seem to be an object at all when using #import (no ISelectionPtr or equivalent) whereas in in the documentation (99.99% for VB, as I'm sure you know :)) it appears to be an object with VB syntax like: appObject.Selection.Font.Style = "bold" I would expect to be able to use something like the following to get a range that corresponded to the selection: msp_excel->GetSelection()->GetRange(); Since it seems that you need a range for nearly everything that you do in Excel, getting a range for the current selection seems like such a common and trivial thing to do, I can't help but feel I am really missing something fundamental here... :-( Thanks, Doug

        Doug Knudson

        R 1 Reply Last reply
        0
        • D Doug Knudson

          Hi Roger, Thanks very much for the response. In answer to your questions... msp_excel is a pointer to the "Application Object" defined as _ApplicationPtr and yes, though strange and at least in the wrapper files (.tlh and .tli) generated by the #import, the Selection is associated with the Application Object, not the sheet. Another strange thing to me is that a Selection does not seem to be an object at all when using #import (no ISelectionPtr or equivalent) whereas in in the documentation (99.99% for VB, as I'm sure you know :)) it appears to be an object with VB syntax like: appObject.Selection.Font.Style = "bold" I would expect to be able to use something like the following to get a range that corresponded to the selection: msp_excel->GetSelection()->GetRange(); Since it seems that you need a range for nearly everything that you do in Excel, getting a range for the current selection seems like such a common and trivial thing to do, I can't help but feel I am really missing something fundamental here... :-( Thanks, Doug

          Doug Knudson

          R Offline
          R Offline
          Roger Stoltz
          wrote on last edited by
          #4

          I suggest you read some about how to automate Excel. Have a look in the references section in this article[^] and see if you can find anything useful for you. I don't think the article itself is of any use for you, but the links may very well be. Hope this helps -- Roger


          "It's supposed to be hard, otherwise anybody could do it!" - selfquote

          "No one remembers a coward!" - Jan Elfström 1998
          "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups