+ Reply to Thread
Results 1 to 12 of 12

How to avoid the hold shift command to unable startup macros?

  1. #1
    Registered User
    Join Date
    01-11-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 2019
    Posts
    74

    How to avoid the hold shift command to unable startup macros?

    Hi,

    So, I have an excel file that opens if a certain filepath on the computer is valid. If it is not valid the excel file will automatically close.

    This code is dependent on the startup macro of the file.

    I just realized that if someone opens the file while holding down shift, they unable this command completely and may use the file however they want.

    Is there any way to avoid this? I mean, I thought about starting a timer as well that search for the file every 5 minutes, but that timer is also dependent on the startup macro.

    Any way I can make my sheet more bulletproof and maybe avoid this silly shift-command trick?
    Last edited by -Citizen; 02-24-2022 at 03:31 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,502

    Re: How to avoid the hold shift command to unable startup macros?

    See: https://bettersolutions.com/vba/events/auto-open.htm

    Basically, if the user holds down the shift key when the workbook is opened, neither approach fires. However, you could run the Auto_Open macro manually.

    If you define a global variable, say, bWBOrun, you can set it to True when either of those macros is run. If you test it, and it is False, you can manually run the Auto_Open macro. Maybe test it as the first thing you do in the Calculate Event handler and/or the Selection Change Event handler.

    Note that, if someone does not enable macros, none of your macros work and functionality is lost.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: How to avoid the hold shift command to unable startup macros?

    Try this method:-

    https://www.teachexcel.com/excel-tut...xcel_1390.html


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Registered User
    Join Date
    01-11-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 2019
    Posts
    74

    Re: How to avoid the hold shift command to unable startup macros?

    Hi!

    Thanks for the reply!

    TMS,

    Just have to ask to be sure what you mean, because when I open the excel file, a message pops up and it starts if the conditions are fullfilled. If not fullfilled than it closes. As you have understood, when holding down shift it basically jumps over the "protection" and the sheet is now wide open and works. However, by using the method you describe here, there will be a macro that is actually testing if the opening macro has been run or not, and if not, it will run the opening macro.

    So, needless to say, running the auto open function every time a formula is being used will be extremely annoing for the user, but you are suggesting that it runs a "check" before it runs the "auto open" function right? So, it checks if it has been run before it runs again?
    Could you show me an example on how this code will be?

    I am sorry, I will probably use so many hours if I am trying to figure it out myself

  5. #5
    Registered User
    Join Date
    01-11-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 2019
    Posts
    74

    Re: How to avoid the hold shift command to unable startup macros?

    Quote Originally Posted by :) Sixthsense :) View Post
    Thanks, I have actually seen this, my only problem is that it may be able to autosave or save (without closing the file) and then copy the file and opening it again using the shift-command and by-passing the security created.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,502

    Re: How to avoid the hold shift command to unable startup macros?

    This example file demonstrates the principle. Please try the attached sample workbook. To be fair, I can't get either of the Open routines NOT to run by pressing the Shift key. Maybe it's my laptop. Anyway, give it a try.

    In the ThisWorkbook module:

    Please Login or Register  to view this content.
    In a Standard module:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    254

    Re: How to avoid the hold shift command to unable startup macros?

    Just out of curiosity, why would anyone hold down shift while opening an excel file?

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,502

    Re: How to avoid the hold shift command to unable startup macros?

    Because they can. And it is supposed to stop the execution of the On Open macro(s) ... just nor for me, at the moment.

  9. #9
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    254

    Re: How to avoid the hold shift command to unable startup macros?

    Isn't that about to be the default setting in the next Office update? How would this effect in the long run when holding shift is no longer required?

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to avoid the hold shift command to unable startup macros?

    Yes, I think so, macros will be disabled by default for downloaded/emailed files with no option to enable them. I think the easiest solution if they need to be distributed is to either sign the code or encourage users to put them in trusted locations.

  11. #11
    Registered User
    Join Date
    01-11-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 2019
    Posts
    74

    Re: How to avoid the hold shift command to unable startup macros?

    Quote Originally Posted by TMS View Post
    Because they can. And it is supposed to stop the execution of the On Open macro(s) ... just nor for me, at the moment.
    Thank you for helping out TMS!

    So, try opening excel (without opening a file), then you chose open, find your file and then try holding shift and double click the file. Then the auto open macros will not run.

    PrizeGotti: The default settings by not enabling macros are basicallly not the same considering that if macros are not enabled, the sheet will not work properly.
    However, this is interesting considering that this may be a problem for all auto open macros and by enabling macros after the sheet is open may not start the auto open macros created.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,502

    Re: How to avoid the hold shift command to unable startup macros?

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Unable to run startup Macro in Excel 2007
    By MartinShort in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-12-2012, 06:57 AM
  2. Macro - Hold view and avoid confirm delete message
    By anmck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2009, 01:06 PM
  3. No Macros; startup message
    By baribill in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2007, 11:35 AM
  4. Replies: 8
    Last Post: 07-22-2006, 11:25 PM
  5. Command Line Startup Switches
    By OldManEd in forum Excel General
    Replies: 1
    Last Post: 02-08-2006, 06:55 PM
  6. [SOLVED] SHIFT doesn't prevent macro from running at startup
    By Jarryd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2005, 05:30 PM
  7. [SOLVED] Unable to load files from alternate startup folder
    By Bill.Carlson in forum Excel General
    Replies: 3
    Last Post: 11-24-2005, 11:40 AM
  8. Command.bar@startup
    By Zurn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2005, 06:32 AM

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