Can macro run automatically in another file from Personal when other file opens?

  • I have a macro I would like to run in a particular file every time it opens, but I cannot put the macro inside that file as we're not allowed to SAVE that particular file.


    Is there a way to set the macro up in the personal macro workbook so that every time the other file opens the macro automatically runs for that file, but that file only?


    Thanks!

  • Re: Can macro run automatically in another file from Personal when other file opens?


    Not without code in the open event of that workbook that would run the code from your personal workbook.

  • Re: Can macro run automatically in another file from Personal when other file opens?


    Quote from royUK;677829

    Not without code in the open event of that workbook that would run the code from your personal workbook.



    Thanks Roy. To be clear: there is no way to run any code for a workbook without first saving some code in that workbook? You couldn't say, put some logic code in the Personal macro wb that said if the other open workbook was xxxx.xls run this macro in xxxx.xls?

  • Re: Can macro run automatically in another file from Personal when other file opens?


    I will offer something as an example - the concept can be moved to PERSONAL.XLSwhatever or created as an add-in but this sample is in a standard workbook.


    There are 2 workbooks. One is called MONITORED.XLSX (Note, no macros) the other is RUNTHISONE.XLSM. Save both to your default documents directory (I didn't bother going to too much trouble for a sample).


    Load runthisone and enable macros. On sheet 1 there's a command button with instructions...


    Try it. nothing will happen until MONITORED.XLSX is opened. Then the contents of cell E5 will be displayedin a MsgBox. The cell will then be updated with the current data and time - just so you can see it interacting with the workbook.


    Close MONITORED.XLSX and click the button again to stop monitoring - if you load MONITORED.XLSX again, nothing will happen...

  • Re: Can macro run automatically in another file from Personal when other file opens?


    Roy, thank you so much for taking the time and effort to put these together to explain it to me. I really appreciate it.

Participate now!

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