+ Reply to Thread
Results 1 to 6 of 6

Please help... How to close excel workbook in specified time

  1. #1
    Registered User
    Join Date
    03-05-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2007 ,Excel 2003
    Posts
    7

    Exclamation Please help... How to close excel workbook in specified time

    Hi,

    I would like to seek some assistance with my work. I can't seem to find a way in creating a macro that would close a certain workbook after 9hours.

    please help... thank you in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Please help... How to close excel workbook in specified time

    Hello there,

    After 9 hours of the workbook being open or are there other conditions?

    Thanks!

  3. #3
    Registered User
    Join Date
    03-05-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2007 ,Excel 2003
    Posts
    7

    Re: Please help... How to close excel workbook in specified time

    Quote Originally Posted by rvasquez View Post
    Hello there,

    After 9 hours of the workbook being open or are there other conditions?

    Thanks!
    Hi,

    yes after 9 hours being open the macro will automatically saves and close the workbook.

  4. #4
    Forum Contributor
    Join Date
    03-15-2007
    Location
    AL, USA
    MS-Off Ver
    2007
    Posts
    174

    Re: Please help... How to close excel workbook in specified time

    Only way I know how to do it is to have an event macro inside the ThisWorkbook object, and then have a module that runs the close code.

    Event macro:
    Please Login or Register  to view this content.
    Close workbook code:
    Please Login or Register  to view this content.
    That one gives the user the choice to save or not, but it's easily modifiable to just save and close

  5. #5
    Registered User
    Join Date
    03-05-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2007 ,Excel 2003
    Posts
    7

    Re: Please help... How to close excel workbook in specified time

    Quote Originally Posted by mshale View Post
    Only way I know how to do it is to have an event macro inside the ThisWorkbook object, and then have a module that runs the close code.

    Event macro:
    Please Login or Register  to view this content.
    Close workbook code:
    Please Login or Register  to view this content.
    That one gives the user the choice to save or not, but it's easily modifiable to just save and close
    Nice... thanks for this... You've been a great help...

  6. #6
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Please help... How to close excel workbook in specified time

    Steps to insert into your workbook

    1. press Alt+F8
    2. Clear the macro name field
    3. In the macro name field type SetTime
    4. Select the Create Option
    5. Visual Basic and a Module will open
    6. Delete the Sub SetTime() and End Sub and replace it with the following code:

    Please Login or Register  to view this content.
    7. On the left hand side there should be a project explorer that has a list of Microsoft Excel Objects and Modules. If you don't see it press Ctrl+R to bring it up.
    If it's there double click on the ThisWorkbook option under the Microsoft Excel Objects folder.

    8. Another blank section should pop up, in this one copy and paste the below code:

    Please Login or Register  to view this content.

    This should do it for you, just close out of Visual basic, close the workbook and reopen.

    Unfortunately, the way the code is set up you won't see the effects until 9 hrs from now. So to test it
    press Alt+F8 and this time select the SetTime macro and select Run. Update this line of code:
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    Save & Close the workbook and then reopen. Wait ten seconds and the workbook should close on it's own.

    Let me know if this works for you!

+ 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