+ Reply to Thread
Results 1 to 15 of 15

Auto Close code preventing access to taskbar

  1. #1
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Auto Close code preventing access to taskbar

    Hopefully this is an easy fix.

    I am using the following code to auto save and close a workbook after it has been open for 15 minutes.

    Please Login or Register  to view this content.
    Due to it being ran as soon as the file is opened, it appears to prevent any Excel security warning message boxes from appearing first, in this case the "Do you want to make this file a trusted document?" does not appear until after the macro is manually stopped... I have a feeling that because of this, all functionality i.e. buttons on the toolbars, being able to close the file etc is lost. Is there a way to ensure warnings are displayed first?

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Auto Close code preventing access to taskbar

    I would guess because the procedure never gets out of this loop
    Please Login or Register  to view this content.
    until either the While statement is False or the code is manually stopped... regardless of 'events' firing, VBA code in any procedure is linear, executing line by line.

    And closing any object while code in the Open event is executing is never a good idea.

  3. #3
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Auto Close code preventing access to taskbar

    Thanks. Is there a way to modify this code to start after any excel warnings are cleared? Or even just to start a set time after the file has been open would solve the issue, so if the code could begin to run 1 minute into the file being open - is this possible?

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Auto Close code preventing access to taskbar

    Have a look at the Application.OnTime method. This executes a procedure at a particular time. Plenty of examples around the place.

  5. #5
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Auto Close code preventing access to taskbar

    Thanks, it appears something like this would work for me:
    Please Login or Register  to view this content.
    With Workbook_Open() being the sub I would like to run after 15 secs.

    Where would I paste the above code, within ThisWorkbook i.e. where the Workbook_Open() sub is, or would I paste in a Module?

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Auto Close code preventing access to taskbar

    The procedure passed to Application.OnTime must be a public Sub in a module.

    You can add the OnTime statement to the Workbook_Open event. Have a look at a recent thread for an example: http://www.excelforum.com/excel-prog...ml#post4592489

  7. #7
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Auto Close code preventing access to taskbar

    Sorry not sure I understand fully, or if I do I can't seem to get it to work.

    In Module1 I have:
    Please Login or Register  to view this content.
    In ThisWorkbook I have:
    Please Login or Register  to view this content.
    I'm receiving an Invalid Use of Property error in Module 1

    I changed the "." to a "_" in application on time as the "." was bringing back an error for some reason

  8. #8
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Auto Close code preventing access to taskbar

    Also found this code which I believe will do the same thing:

    Please Login or Register  to view this content.
    I don't understand what I need to put within the speech marks, if someone could explain it would be most helpful.

    My ThisWorkbook code is in post #1... this is what I wish to call/start but after 10secs rather than as soon as the file is opened

  9. #9
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Auto Close code preventing access to taskbar

    Sorry, but you don't understand at all...

    Application.OnTime is a method of the Excel application - not a procedure you write. Anything that has a dot notation is a method or property of an object - you should look up 'methods' and Property' of objects in VBA.

    The basic idea is you set up the OnTime method in the Workbook Open event. That call to OnTime defiines a time the procedure is to run and the procedure name. The procedure to run must be a public Sub in a module. Also, going back to the "Workbook_Open() being the sub I would like to run after 15 secs" comment, Workbook_Open is an event triggered when the workbook is opened, you cannot delay that running.

    In the Workbook_Open event add some code like
    Please Login or Register  to view this content.
    'NameOfProcedure' is a sub in a standard code module.

    Now if you read the posts in the link I added in post #6 it might be clearer.
    Last edited by cytop; 03-03-2017 at 07:19 AM. Reason: Link to Events page

  10. #10
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Auto Close code preventing access to taskbar

    This makes more sense now, thank you for explaining.

    Isn't the procedure I wish to run in this instance happen to be in ThisWorkbook though rather than a Module?
    From my code in the first post, what I wish to run is the TimeInMinutes stuff, so wouldn't the code I need be this:
    Application.OnTime Now + TimeValue("00:00:15"), "TimeInMinutes"

    It can't be exactly this as my Time warning box still appears instantly so it's not working, but I feel I'm getting closer...
    Last edited by JRC1; 03-03-2017 at 07:51 AM.

  11. #11
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Auto Close code preventing access to taskbar

    Quote Originally Posted by FRC1
    Isn't the procedure I wish to run in this instance happen to be in ThisWorkbook though rather than a Module?
    Please see
    Quote Originally Posted by Post #9
    The procedure to run must be a public Sub in a module
    Quote Originally Posted by Post #6
    The procedure passed to Application.OnTime must be a public Sub in a module.
    The call to Application.Ontime is in the Workbook_Open event.

  12. #12
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Auto Close code preventing access to taskbar

    Ok so:

    ThisWorkbook =
    Please Login or Register  to view this content.
    Module1 =
    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Auto Close code preventing access to taskbar

    It may not seem it to you but this is actually very simple - but you really should try to understand what is posted.

    Post #9:
    In the Workbook_Open event add some code like
    Please Login or Register  to view this content.
    'NameOfProcedure' is a sub in a standard code module.
    Application.OnTime is a method of the Excel application - not a procedure you write
    As far as "what do I put here" goes that is explained in detail in the help files as is the exact syntax for Application.OnTime
    Last edited by cytop; 03-03-2017 at 08:34 AM.

  14. #14
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Auto Close code preventing access to taskbar

    Tell you what, it's lunch time - I'm out of here. Sample workbook attached.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    02-20-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    133

    Re: Auto Close code preventing access to taskbar

    Quote Originally Posted by cytop View Post
    Tell you what, it's lunch time - I'm out of here. Sample workbook attached.
    Thanks. This still doesn't help explain to me what I'm after though... This brings up a text box after 15 secs... but all I want to happen after 15 secs is my code to run... i.e. my code within ThisWorkbook.

    I don't want anything to appear, I don't wish to create a new sub to start, I think this is where the confusion is...
    As soon as my workbook is opened, my code within ThisWorkbook runs... i.e. the code which starts a timer on closing the workbook after x minutes... I just want to delay it running by 15 secs... surely it is simpler than this?!
    Last edited by JRC1; 03-03-2017 at 11:15 AM.

+ 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. Adding auto-close code to existing?
    By barbd777 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 07-25-2016, 06:51 PM
  2. if file is closed from taskbar icon vba addin menu does not close with it
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-09-2016, 10:33 AM
  3. Replies: 1
    Last Post: 01-31-2016, 05:54 AM
  4. Preventing Save or Close Unless Cells are Filled
    By shafih786 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-13-2015, 06:28 AM
  5. VBA Code for Preventing Save or Close (conditional)
    By hiteshkumar21483 in forum Excel General
    Replies: 5
    Last Post: 12-29-2014, 01:33 PM
  6. Need help with auto close code
    By revlemmon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2012, 07:31 AM
  7. Preventing Access ??
    By Mhz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2007, 07:27 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