+ Reply to Thread
Results 1 to 15 of 15

Macro causes multiple instances of Excel in Task Manager

  1. #1
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Macro causes multiple instances of Excel in Task Manager

    I have a workbook with an open event that gathers data from some number of closed workbooks. Each time I run the code another instance of Excel is added to the Task Manager. How do I prevent a second instance of Excel, or how do I close that second instance with in my code.

    This has me stumped. Any help would be great.

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Macro causes multiple instances of Excel in Task Manager

    Not sure what u are using xl for. You can still set the workbook without make a new instance of excel (This is what fill your taskmanager with another excel), since you running this within Excel.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro causes multiple instances of Excel in Task Manager

    I tried removing xl, which I had defined as "New Excel.Application". When I run the code it looks at one workbook and then bails.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro causes multiple instances of Excel in Task Manager

    The code creates a new instance, xl, of Excel but doesn't close it.

    I agree with six that you could probably run this code without the new instance but if you must have it then make sure you close it.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro causes multiple instances of Excel in Task Manager

    I replaced
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    . This does prevent the second instance of excel! but when I open the workbook it it is not getting all of the data, but if I step through the code everything comes through fine.
    I tried moving
    Please Login or Register  to view this content.
    to the end of my code but that did not keep the second instance of Excel from showing up and it was not getting all of the data.

    Oh and
    Please Login or Register  to view this content.
    is a bad line I was trying to something I had found doing a Google search, and I missed that line when I deleted that set of code.

  6. #6
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro causes multiple instances of Excel in Task Manager

    Actually I still need
    Please Login or Register  to view this content.
    and it needs to be before the quit. If I dont have the close than Excel thinks that the workbooks being acssessed are being closed improperly and creates a backup of the file.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro causes multiple instances of Excel in Task Manager

    I wasn't suggesting replacing this.
    Please Login or Register  to view this content.
    To close the instance of Excel you need to add this.
    Please Login or Register  to view this content.
    It would go at the end of the code after you've dealt with all the workbooks.

  8. #8
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro causes multiple instances of Excel in Task Manager

    I tried leaving
    Please Login or Register  to view this content.
    where it belongs and put
    Please Login or Register  to view this content.
    at the end of the code. after running the code I still have 2 instances of Excel, but everything works fine.
    if I combine
    Please Login or Register  to view this content.
    and run the code there is only 1 instance of Excel but it does not pull all of the data. if I step through it everything works.

  9. #9
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro causes multiple instances of Excel in Task Manager

    Okay. Not sure if this is the best fix but it seems to work. I placed
    Please Login or Register  to view this content.
    right be for the
    Please Login or Register  to view this content.
    loop. This prevents the second instance of excel.
    I removed the error trap located here.
    Please Login or Register  to view this content.
    I am traping for errors here though
    Please Login or Register  to view this content.
    I added this trap since I was getting a run-time error 13 when I ran the code, but when I step through the code everything worked great.

    here is the new working code.
    Please Login or Register  to view this content.
    I solved my problem but I think there might be a better way.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro causes multiple instances of Excel in Task Manager

    One way which possibly might be better is not using a separate instance of Excel.

    By the way, it would make more sense to have xl.Quit after the Next.

    By the way, what error are you meant to be handling here?
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro causes multiple instances of Excel in Task Manager

    If I move the xl.Quit after the next there is still a second instance of Excel after I run through the code.

    If I dont have the
    Please Login or Register  to view this content.
    then this line
    Please Login or Register  to view this content.
    generates a run-time error 13 when I run through the code. The odd thing about this error though is, I dont get it when I step through the code. Any thoughts?

    I will try doing everything with in the active workbook.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro causes multiple instances of Excel in Task Manager

    Not the active workbook, the existing instance of Excel.

    By the way throughout the code you hardly ever use the references, xl and xlw1.

    When I've seen code like that, normally when automating Excel from other applications, there is a tendency for multiple 'ghost' instances of Excel to be found after the code has finished executing.

    Another problem I see is this which is halfway through the code.
    Please Login or Register  to view this content.
    That doesn't close the instance of xl, it'll still be running.
    Last edited by Norie; 10-14-2013 at 10:55 AM.

  13. #13
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro causes multiple instances of Excel in Task Manager

    Okay, I reworked the code so that it now runs in the existing instance of Excel. While this does prevent the second instance of Excel, I dont like how the screen "flickers" each time the closed workbook is opened even though I have the screen updating turned off. I am not sure who to fix this problem though.

    As for xl = Nothing; I am not trying to close the appliction, I am attempting to free memory. This was one of my first VBA code projects so I didnt know much about coding. I have now moved it to the end of the code.

    Please Login or Register  to view this content.

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro causes multiple instances of Excel in Task Manager

    Getting rid of any selecting and activating will probably help get rid of any screen flickering.

  15. #15
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro causes multiple instances of Excel in Task Manager

    I am not selecting anything in the closed workbook. The code is looking at cells for value but it is not selecting them. when I step throug the code, the flicker happens on this line.
    Please Login or Register  to view this content.

+ 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. VBA not closing excel (visible in the task manager)
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-01-2013, 08:43 AM
  2. Excel Instance not closing in task manager.
    By MattShoreson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2009, 11:26 AM
  3. excel 2003 Resides in Task manager.
    By Pandi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-09-2006, 10:50 AM
  4. excel.exe is not terminating from task manager
    By Inthi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2005, 09:45 AM
  5. Task Manager and Excel 2003
    By Mike in forum Excel General
    Replies: 1
    Last Post: 04-20-2005, 06: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