+ Reply to Thread
Results 1 to 12 of 12

Automatically run Personal.xls when a particular Excel file is opened

  1. #1
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Automatically run Personal.xls when a particular Excel file is opened

    Can I get Personal.xls code or any other code to run when a particular Excel file opens?
    What I'm thinking is that, since Personal.xls will open when Excel is started, it may be possible to get the code in Personal.xls to run automatically, and to check whether the file I want to use is also open. If it isn't, exit the code, but if it is, then run the rest of the code.
    Up to now, I've used a Command Button UserForm to start the code in Personal.xls, after first opening the file I want to use.
    Are there any dangers in doing this? The code is to be used by several people in a LAN.
    Thanks in advance.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Automatically run Personal.xls when a particular Excel file is opened

    do they all have the same personal.xls? can't you put the code in the file that is being opened instead?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Re: Automatically run Personal.xls when a particular Excel file is opened

    Thanks for the suggestion.
    Can't do that though - the file I want to use is a temporary file generated by exporting data from MS CRM. The file is created new each time.

  4. #4
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Automatically run Personal.xls when a particular Excel file is opened

    You can run based on file name. The code will probably look like

    Please Login or Register  to view this content.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Automatically run Personal.xls when a particular Excel file is opened

    I'd create an add-in for them that uses application event monitoring to check each file they open-see this page for details http://www.cpearson.com/Excel/AppEvent.aspx

  6. #6
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Re: Automatically run Personal.xls when a particular Excel file is opened

    Thanks for the suggestions.

    JosephP, I had a look at the link and at some pages linked to that to try to get my head around application event monitoring, but alas, I fear it is a bridge too far for me at the moment. I didn't understand what I was reading.

    JieJenn, I originally couldn't get your idea to work, as Personal.xls runs before the Temp workbook has opened. However, in trying to get my head around JosephP's idea, I came across OnTime, which allowed me to delay the execution of Personal.xls until the Temp file had opened.


    In the ThisWorkbook module:

    Please Login or Register  to view this content.
    In the main module (I had to use a wildcard in the Temp file name, and use "Like", as the file name has a random number in it each time):

    Please Login or Register  to view this content.
    I'd be interested to know what you think of this. Can it be improved?

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Automatically run Personal.xls when a particular Excel file is opened

    Automation is always a fun project, eh?

    I would use a different tack. I would put a standard, normal macro into my Personal file, and assign a unique keyboard shortcut to it. Then I'd just call that macro anytime I wanted by pressing the keyboard shortcut when the file was active. You could still build a "check" into the macro to make sure the file was available and abort if not, but then I wouldn't have to quit excel and relaunch to fire timers, the macro would always be available.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Automatically run Personal.xls when a particular Excel file is opened

    +1 for JB's suggestion -- it's simple to implement.

    Joseph's suggestion is almost as simple. In the ThisWorkbook module of Personal (or better, an add-in)

    Please Login or Register  to view this content.
    In a code module,
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Re: Automatically run Personal.xls when a particular Excel file is opened

    Many thanks Beaucaire and shg.

    I had actually already set the thing up with a shortcut, but then thought better of it. Some of the people who will be using this can get a bit flustered at times, particularly where technology is concerned, so I wanted to make it as easy as possible. Some forget shortcuts too. Also, they use a lot of shortcuts for various things (they do remember them eventually), and it could be difficult to find something unique (is it true that we are limited to making shortcuts with the Ctrl key only?)

    I will try B's suggestion, although I don't really follow it (and I have the added joy of trying to get it to work with a wildcard in the filename), and it might have to wait a bit, as it's now 4.30 in the morning and my eyes are complaining. You probably know what I mean. I'm even typing (slowly) in the dark as my wife is sleeping nearby.

    I'm a bit concerned about using an addin, as it seems to me that it would have to be installed on all the computers, and that would make it difficult to edit - or am I wrong about that?

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Automatically run Personal.xls when a particular Excel file is opened

    I'm a bit concerned about using an addin, as it seems to me that it would have to be installed on all the computers, and that would make it difficult to edit ...
    So would a Personal file.

    If people have a common network share, you can put the add-in there, and make it read-only, which would enable you to maintain it without it getting locked, and without having to go around changing everybody's Personal workbook.

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Automatically run Personal.xls when a particular Excel file is opened


  12. #12
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Re: Automatically run Personal.xls when a particular Excel file is opened

    Ahhh. Thank you both. I had planned to put the Personal file on our server and make it read only. So if I can also do that with an Addin, I guess that's the way to go... Let's see if I can work out addins now.

+ 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