+ Reply to Thread
Results 1 to 6 of 6

GetObject not picking running excel files

  1. #1
    Registered User
    Join Date
    06-03-2011
    Location
    Chennai, TamilNadu
    MS-Off Ver
    Excel 2003
    Posts
    1

    Question GetObject not picking running excel files

    I am trying to get opened instances of excel application and operate between them.

    Please Login or Register  to view this content.
    I have 2 excel files in open and while running the code xlApp.Workbooks.Count always 0.
    But GetObject("", "Excel.Application").Application.Name returns Microsoft Excel and GetObject("", "Excel.Application").Application.hwnd returns a valid handle.

    Also I tried with Set xlApp = GetObject("", "XLMAIN") which throws error ActiveX can't create object
    Why it is not picking the running excel files and give count? Any ideas?

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: GetObject not picking running excel files

    Hi scvel and congratulations on your first post.

    The files associated with Post #2 in the following thread may help you. http://www.excelforum.com/excel-prog...instances.html

    Lewis

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: GetObject not picking running excel files

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: GetObject not picking running excel files

    Hi Orrin,

    I think you might have misread the question. I think the OP wants to access workbooks in different instances of Excel.

    Lewis

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: GetObject not picking running excel files

    Hi Lewis,

    Yeah, I thought that I might be oversimplifying - but it looked like the book with the macro wasn't being excluded

  6. #6
    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: GetObject not picking running excel files

    Hello scsvel,

    Welcome to the Forum!

    Sorry this to so long, but as you will see this is a simple question with a complex solution. To access another workbook in a separate instance of Excel requires using the Windows API to return a reference to the other workbook. Each instance of Excel runs in it's own separate process and by Windows law can not directly access the process of another object. With the API, it can be done indirectly.

    This code works on 32 bit Windows systems. If you are running exclusively a 64 bit Windows system, this code will fail. I have not written a 64 bit version yet.

    Copy all this code and paste it into a new VBA Module in your workbook. The macro finds all running Excel workbooks and returns information in a 1 based 2-D array about the Active Workbook in each Excel instance.

    Return Array Description
    xlInstances(m, n) - m is from 1 to 4, n is from 1 to the number of Excel instances

    m(1) = The Excel Workbook object
    m(2) = The Excel workbook Title
    m(3) = The window handle of the Excel application
    m(4) = The Process ID

    Module Macro Code
    Please Login or Register  to view this content.
    Test MAcro
    Please Login or Register  to view this content.
    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!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Folder Picker - picking files in chronological order
    By jcroque89 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-28-2015, 05:12 PM
  2. How to work on other excel files while running a macro?
    By manohar.sv in forum Excel General
    Replies: 3
    Last Post: 12-02-2008, 07:34 AM
  3. [SOLVED] Files open only when excel is already running
    By stratos@laspas.gr in forum Excel General
    Replies: 2
    Last Post: 05-25-2006, 04:35 AM
  4. GetObject Function On Text Files
    By William Horton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2005, 05:05 PM
  5. GetObject method from excel to other application from remote server
    By sandra mangunsong via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-24-2005, 04:06 PM

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