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.
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.
Hello there,
After 9 hours of the workbook being open or are there other conditions?
Thanks!
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: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![]()
Please Login or Register to view this content.
![]()
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:
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.![]()
Please Login or Register to view this content.
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:
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.![]()
Please Login or Register to view this content.
Let me know if this works for you!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks