+ Reply to Thread
Results 1 to 7 of 7

Workbooks.Count doesn't work when excel cell is active

  1. #1
    Registered User
    Join Date
    05-05-2009
    Location
    Cambridge, MA, US
    MS-Off Ver
    Excel 2003
    Posts
    3

    Workbooks.Count doesn't work when excel cell is active

    I'm using IronPython (Python for C#) to access Excel via COM, but it looks like the COM interface is what's giving me trouble, so this should also apply to VBA. I notice that Application.Workbooks.Count only works sometimes. If I have a handle on Excel, I can usually go through the workbooks without any problems. However, if I double click on a cell in excel to enter the edit mode, I cannot access Workbooks.Count property. Listing all COM object properties on Workbooks, it looks like it just becomes an primitive object with no real properties. Here are all the properties of Workbooks collection when excel is not in an in-cell edit mode:

    ['Add', 'Application', 'CanCheckOut', 'CheckOut', 'Close', 'Count', 'CreateObjRef', 'Creator', 'Equals', 'Finalize', 'GetEnumerator', 'GetHashCode', 'GetLifetimeService', 'GetType', 'InitializeLifetimeService', 'Item', 'MakeDynamicType', 'MemberwiseClone', 'Open', 'OpenDatabase', 'OpenText', 'OpenXML', 'Parent', 'Reduce', 'ReferenceEquals', 'ToString', '_Open', '_OpenText', '_OpenXML', '__OpenText', '__class__', '__doc__', '__getitem__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__']

    and here are all the properties when excel is in in-cell edit mode:

    ['CreateObjRef', 'Equals', 'Finalize', 'GetHashCode', 'GetLifetimeService', 'GetType', 'InitializeLifetimeService', 'MakeDynamicType', 'MemberwiseClone', 'Reduce', 'ReferenceEquals', 'ToString', '__class__', '__doc__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__']

    Is there a different way to access workbooks? Or maybe there's a property on the Application object that could tell me if workbooks are accessible? Any help is appreciated, thanks!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Workbooks.Count doesn't work when excel cell is active

    Hello nivanov,

    IronPython is designed to work with the VB.Net framework. All COM library access is through VB.Net and not VBA. You need to post your question in a VB.Net group. The only thing VBA and VB.Net have in common is the letters VB. They are very different languages and not interchangeable.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    05-05-2009
    Location
    Cambridge, MA, US
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Workbooks.Count doesn't work when excel cell is active

    You are right in that IronPython works with .NET. However, as I mentioned above, it looks like it's a problem with Excel's COM interface, not IronPython's ability to connect to it. VBA also uses COM (as far as I know) so I figured this would be a good place to post this question. If it isn't, could you direct me to the appropriate forum section?

    Thanks!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Workbooks.Count doesn't work when excel cell is active

    In VBA, you can't run code when when Excel is in Edit mode.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Workbooks.Count doesn't work when excel cell is active

    Hello nivanov,

    Here are 2 Microsoft groups you can try. One is for .Net and the C#. Between these you should be able to find an answer.

    microsoft.public.dotnet.languages.vb
    microsoft.public.dotnet.languages.csharp

  6. #6
    Registered User
    Join Date
    05-05-2009
    Location
    Cambridge, MA, US
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Workbooks.Count doesn't work when excel cell is active

    to shg: Is there a way to query excel if it's in edit mode? I need to determine if excel is willing to accept COM commands. Thanks!

    to Leith Ross: Thanks, I'll check them out.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Workbooks.Count doesn't work when excel cell is active

    : Is there a way to query excel if it's in edit mode?
    No clue. I'm a VBA guy.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1