+ Reply to Thread
Results 1 to 9 of 9

Macros randomly failing when file opened

  1. #1
    Registered User
    Join Date
    01-08-2009
    Location
    Lincoln, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Macros randomly failing when file opened

    Hi all,

    I have an annoying problem. I have built an excel based database of clients and employees for my company. Each client and employee has their own file to avoid monster file sizes. There are a number of ways to load a file all run by macros. The problem I am having is that approximately 50% of the time when it opens the client record and closes the main file, the macros in the client file will not work. It just says that the macro cannot be found or macros may be disabled. I can close the file, not saving changes and then re-open the same record using the exact same method as before and all macros work fine. Anyone got any ideas as its becoming a real pain!!

    Thanks in advace!
    James

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello James,

    Welcome to the Forum!

    You don't say if these files are shared or not, just that each client and employee has their own file. Without seeing the macro code you are using, it is impossible to accurately diagnose the cause of the problem.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    01-08-2009
    Location
    Lincoln, England
    MS-Off Ver
    Excel 2007
    Posts
    7
    Hi Leith,

    Thanks for the reply. Firstly, the files are not shared. They are all accessed and stored on the same computer. the reason each client/employee has their own file is each one has 6 sheets dedicated to them and that would obviously cause problems if you had 100 clients or more all in the same file.

    As I said there are many ways a client file can be opened from the main file. All of them use the same coding and the same problem happens completely at random. This is the coding I use.


    Please Login or Register  to view this content.

    I still don't think this is a coding issue but I am all out of ideas.
    I'ts getting really frustrating now so ANY help would be greatly appreciated!!

    One thing that may be worth noting is that if I load a file and the marcos fail, I close the file go back and re-load it in the same way and it works fine. I've never had the same file fail twice in a row.

    Thank you!
    James

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    hi James
    It may not make any difference but I suggest explicitly referencing the file that the below sheets are part of by changing your code from
    Please Login or Register  to view this content.
    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  5. #5
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    & for the sub you can use With statements ie
    Please Login or Register  to view this content.
    hth
    Rob

  6. #6
    Registered User
    Join Date
    01-08-2009
    Location
    Lincoln, England
    MS-Off Ver
    Excel 2007
    Posts
    7

    Thumbs up

    Hi Rob,

    I have replaced the code with your suggestion, and so far so good. I've tested it with 10 different client files and had no issues. I still don't understand how it relates to macro security but one thing I have come to learn with computers is you don't NEED to know how something works... just that it DOES work!!

    Cheers for the help!
    James

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    I don't have Excel 2007 so I can't be sure on macro security requirements without some research (& that's for you to do ;-)). However, I suspect that if you were opening more than one file at once the macro could have been getting confused. Without the explicit references to the relevant workbook, the "sheets(..."code will default to the currently active workbook & it may end up trying to open the wrong file at some stage.

    anyway, it works :-)

    Rob

  8. #8
    Registered User
    Join Date
    01-08-2009
    Location
    Lincoln, England
    MS-Off Ver
    Excel 2007
    Posts
    7
    it DID work! but it was just teasing me! I'm only opening a single file at a time. The fact that it happens seemingly at random suggests to me that it MIGHT be a bug in excel rather than my programming. Thanks for the help anyway Rob!

    James

  9. #9
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    There could be a bug, but being a being a bit of a sceptic I think the answer is still out there... somewhere ;-)

    Do you have any other code that may be playing a part in the problem?
    Does Excel 2007 have a similar function to Excel 2003 under Tools-Macros-Security?
    What happens if you change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    - in fact, what happens when using the below modification?

    Please Login or Register  to view this content.
    hth
    Rob

+ 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