Stop Auto_open macro running in other open workbooks

  • Hi


    I have an auto_open macro which auto refreshes a pivot table in workbook A on opening and the pivot refreshes every 1 minute. This works fine but when I open another unrelated Excel workbook B, the auto_open macro in workbook A runs again and re-opens workbook A even when I close down workbook A.


    I've noticed that in the VBA editor that the VBA modules for workbook A appear in the VBA editor in workbook B even though I have closed down workbook A.


    I've tried using Private sub auto_open in a module thinking it would stay away from other workbooks and workbook_open in the workbook but no luck. Could it be the timer I've added?


    My code is tagged.


  • Re: Stop Auto_open macro running in other open workbooks


    Probably not the most elegant solution, but you could wrap all your pivot table code in an if condition, and test the activeworkbook.name property:


  • Re: Stop Auto_open macro running in other open workbooks


    Infomage


    Wowser - this seems to have solved my problem although it reloads the first time but when I close it the second time it stays off.


    Thanks very much for your advice.

  • Re: Stop Auto_open macro running in other open workbooks


    The problem is with Application.OnTime not AutoOpen, you need to cancel the OnTime when you close workbook A or Excel/VBA will keep on trying to run it and to do that it needs to open workbook B.

    Boo!:yikes:

  • Re: Stop Auto_open macro running in other open workbooks


    If you only want the timer to run when the workbook with the pivots is active, use the workbook.activate and workbook.deactivate events to start and stop it respectively.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!