+ Reply to Thread
Results 1 to 6 of 6

Macros run slow after loading another workbook, and fast if I re-open Excel?

  1. #1
    Registered User
    Join Date
    11-07-2012
    Location
    Newcastle, UK
    MS-Off Ver
    2010
    Posts
    31

    Macros run slow after loading another workbook, and fast if I re-open Excel?

    Apologies if this has been answered previously - I couldn't think of a search term that wouldn't bring up a large number of results!

    This is a document I'm developing at work, so unfortunately I cannot upload it for people to test with. I could provide blanked out screenshots if required, but I hope this won't be necessary.

    I have an Excel file (I'll refer to as the 'master file'), which I use to build up a report (consisting of rows of data). It has quite an extensive front panel which utilises a large number of macros. The master document is ~6 MB in size and has ~300 worksheets (most of which are back-end and xlveryhidden).

    Colleagues will be using the master file to generate reports. They may want to send the data to other people, and so to assist with this, I have developed an import/export feature, which saves a new document which only contains the data (none of the macros, front panel, etc.). Not only does this mean that there is less risk of the master document getting into the wrong hands, but it also means that the file they send is significantly reduced in filesize (~200 KB rather than 6 MB), as it only contains the bare essentials.

    So, that's a bit of the background, here comes the problem...

    I have recently discovered an issue with the master file. When I import data using my own import feature, it opens the small Excel file that contains the data, copies the data into the master file, then closes the small Excel file. Once this has completed, however, the macros in my document run significantly slower (often 5-10 times slower than normal). Given that some of these macros take a few seconds to run at the best of times, this can be unbearably slow.

    My first thought was that it was running slower because it was having to calculate the extra cells associated with the imported data, however, I found that if I removed all the data after importing, it would still run significantly slower than normal.

    I have found one solution, but it is by no means ideal. If I import the data, save the master file with the data imported, close Excel, and re-open the master file, the macros run reasonably fast - not quite as fast as before the data is imported, but significantly faster than if I had imported and not saved/closed.

    I tried searching online for a solution to this problem, but couldn't find anything concrete. Through my search, I read (here) that "Excel does not release all memory when workbooks are closed". Would I be right in thinking this is the likely cause of the slowdown in macro runtime? If it is, is there a possible solution that does not involve me having to save and close Excel then re-open the file?

    A key reason for the import/export feature was so that the user doesn't have to save the data in the master file, so ideally I would like to avoid using this as a solution.

    Any help would be greatly appreciated. If you need more information, please let me know!

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Macros run slow after loading another workbook, and fast if I re-open Excel?

    The freeing up of memory shouldn't really be an issue because the subordinate/export file is small in comparison to the master. Maybe it's setting the calculation mode to automatic ???
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    11-07-2012
    Location
    Newcastle, UK
    MS-Off Ver
    2010
    Posts
    31

    Re: Macros run slow after loading another workbook, and fast if I re-open Excel?

    Quote Originally Posted by AndyLitch View Post
    The freeing up of memory shouldn't really be an issue because the subordinate/export file is small in comparison to the master. Maybe it's setting the calculation mode to automatic ???
    I've done all of the usual Application.Calculation and Application.ScreenUpdating settings during the running of the macros, but they're set to normal (xlCalculationAutomatic and True respectively) afterwards.

    If it were a case of calculation mode, that wouldn't explain why it is only slow once I have imported the data (or why it is fast if I save/close/re-open Excel). Even if I delete the imported data, it is still slower than before, despite there not being any additional data to have to calculate.
    Last edited by Pedsdude; 09-19-2013 at 06:16 AM.

  4. #4
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Macros run slow after loading another workbook, and fast if I re-open Excel?

    Hi everyone

    Actually I am facing a similar issue, the macro runs perfectly fine, and then suddenly in takes upto 2 minutes (when before it was at 1 second)
    Used Range does not change, so seems to be a similar issue as for Pedsdude

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

    Can you post some examples of the code you are using?

    By the way, do you need to store all 300 worksheets in this workbook?

    If the workbook becomes corrupt there's a good chance you'll lose all the data on the 300 worksheets.
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    11-07-2012
    Location
    Newcastle, UK
    MS-Off Ver
    2010
    Posts
    31

    Re: Macros run slow after loading another workbook, and fast if I re-open Excel?

    Norie,

    It's a rather extensive user interface with a large amount of VBA coding behind it. Unfortunately I'd like to not post the code because (a) there's so much of it that I doubt it would be of any use unless someone was willing to spend many hours understanding what it does and how it all interacts, and (b) it's something I'm working on as part of my job and much of it is confidential.

    I was more hoping there would be a fundamental issue / cause here that may be apparent to someone who knows more about Excel than I do. I don't think it's the macros themselves that are causing the issue here, as the same macros run at different speeds before and after re-opening the document. It seems to me that Excel itself is becoming sluggish in general following the import, rather than data causing the macros to slow down.

    Unfortunately I do need 300 worksheets - they contain product information and different values are shown on the front page depending on the options selected. I could potentially combine some of these worksheets, but it would make updating them more labour intensive. The user never sees these worksheets and they do not contain too much data, so I don't think it is too much of an issue. I've been making frequent backups of the file during development, so I don't believe I'm at risk of losing any data as a result of it becoming corrupt.

+ 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. A fast way to open a workbook as read-only
    By Raymond85 in forum Excel General
    Replies: 11
    Last Post: 01-13-2013, 06:52 PM
  2. excel 2010 very slow to open/save workbook
    By bebe123 in forum Excel General
    Replies: 10
    Last Post: 01-06-2011, 11:10 AM
  3. [SOLVED] Excel Workbook slow to open
    By Sandy M in forum Excel General
    Replies: 2
    Last Post: 01-09-2006, 05:15 PM
  4. Disable Macros when loading a Workbook in Excel 2000
    By Remy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-16-2005, 04:10 PM
  5. [SOLVED] identical macros run fast and slow
    By markwattwood in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-08-2005, 04:15 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