+ Reply to Thread
Results 1 to 12 of 12

Worsened macro performance if called from another macro?

  1. #1
    Registered User
    Join Date
    11-16-2011
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    6

    Worsened macro performance if called from another macro?

    Hi,

    I have a quite heavy macro that takes 5-10 minutes to run since it includes a lot of simulations. I now face a situation where I would like to run this macro in ~50 different files, all different versions of the one containing the heavy macro. The "outer macro" would be quite simple, fetching the names of the files to be opened, simulated, saved and closed using a loop:
    Please Login or Register  to view this content.
    So to my question: Will this way of running the "heavy macro" worsen its performance, compared to doing it manually? I get the impression that the heavy macro runs much slower if called from an "outer macro", but it would be very helpful with some actual facts on how this works.

    Many thanks in advance.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Worsened macro performance if called from another macro?

    Hi,

    Don't think it should run any slower.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,334

    Re: Worsened macro performance if called from another macro?

    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    Read this to understand why we ask you to do this, then please edit your first post to include links to any and all cross-posts in other forums.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    11-16-2011
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Worsened macro performance if called from another macro?

    I apologise for the rule-breaking, and I'll make sure to include a link from my post in the MrExcel.com forum.

    Quote Originally Posted by romperstomper View Post
    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    Read this to understand why we ask you to do this, then please edit your first post to include links to any and all cross-posts in other forums.

  5. #5
    Registered User
    Join Date
    11-16-2011
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Worsened macro performance if called from another macro?

    Thanks, I'll hope for this hypothesis to hold :-).
    Quote Originally Posted by Domski View Post
    Hi,

    Don't think it should run any slower.

    Dom

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Worsened macro performance if called from another macro?

    If the workbooks won't be visible the macro will run faster (no screenupdating for example):

    Please Login or Register  to view this content.



  7. #7
    Registered User
    Join Date
    11-16-2011
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Worsened macro performance if called from another macro?

    Ok, so your code doesn't open the workbook with the heavy macro as such, but rather runs the macro and saves the results -- correct?

    If so, it definitely seems like a more efficient way to run the macro 40 times than having to open each file with the Workbooks.Open command -- opening one of these workbooks actually takes another 2 minutes each time due to their inherent complexity.
    Quote Originally Posted by snb View Post
    If the workbooks won't be visible the macro will run faster (no screenupdating for example):

    Please Login or Register  to view this content.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,334

    Re: Worsened macro performance if called from another macro?

    No, the workbooks still get opened - you just don't see them.

  9. #9
    Registered User
    Join Date
    11-16-2011
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Worsened macro performance if called from another macro?

    Thanks!

    Unfortunately, the With GetObject solution does not seem to allow the heavy macro to run properly -- there is an "out of range" error when it is supposed to select a specific sheet in the workbook containing the heavy macro using Sheets("Sheet1").Select

    It seems I'll have to stick with the original solution after all.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Worsened macro performance if called from another macro?

    Why don't you trigger the macro when opening the file ?

    Please Login or Register  to view this content.
    So what the other macro has to do is only:
    Please Login or Register  to view this content.
    Last edited by snb; 11-16-2011 at 10:56 AM.

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,334

    Re: Worsened macro performance if called from another macro?

    To be honest, I can't see why there would be a difference in the way that the workbook is opened. If the sheet is in the workbook with the code, there should not be an issue.

  12. #12
    Registered User
    Join Date
    11-16-2011
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Worsened macro performance if called from another macro?

    I would now also agree with you from practical experience. I discovered the reason for the slow performance was that I had forgot to set recalculation to manual in the general Excel settings. This caused the heavy simulations to run very slowly, thus prompting my initial question.

    Thanks a lot for pointing me in the right direction!
    Quote Originally Posted by romperstomper View Post
    To be honest, I can't see why there would be a difference in the way that the workbook is opened. If the sheet is in the workbook with the code, there should not be an issue.

+ 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