[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Excel workbook auto save/close after inactivity

Posted on 2012-03-15
8
Medium Priority
?
1,618 Views
Last Modified: 2012-03-16
Hello:

I would like a macro that runs in the back ground in excel that would save the workbook and close it after a given time frame if there was no activity by the user.
0
Comment
Question by:DavidH7470
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:costaf
ID: 37725251
hi, there. if i´m not mistaken there is an option in Excel 2010 Save options that allows you to auto save  every x minutes , and it saves your workbook automaticly , even if you close the document without saving it.
0
 
LVL 21

Accepted Solution

by:
netcmh earned 2000 total points
ID: 37725252
0
 
LVL 15

Expert Comment

by:jerseysam
ID: 37725261
Dim DownTime As Date


Sub SetTime()
DownTime = Now + TimeValue("00:00:20")
Application.OnTime DownTime, "ShutDown"
End Sub


Sub ShutDown()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub


Sub Disable()

On Error Resume Next
Application.OnTime EarliestTime:=DownTime, Procedure:="ShutDown", _
Schedule:=False
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DavidH7470
ID: 37725352
Hi Jerseysam

That works to a point.  But it closes even as a user is entering information.  I was looking for it close it after an interval of inactivity.

Thanks
0
 
LVL 21

Expert Comment

by:netcmh
ID: 37725370
The link I provided has the inactivity close segment.

Private Sub Workbook_Open()
MsgBox "This workbook will auto-close after 20 seconds of inactivity"
Call SetTime
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Disable
End Sub


Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Call Disable
Call SetTime
End Sub


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target _
As Excel.Range)
Call Disable
Call SetTime
End Sub
0
 
LVL 21

Expert Comment

by:netcmh
ID: 37725372
the module would have:

Dim DownTime As Date


Sub SetTime()
DownTime = Now + TimeValue("00:00:20")
Application.OnTime DownTime, "ShutDown"
End Sub


Sub ShutDown()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub


Sub Disable()

On Error Resume Next
Application.OnTime EarliestTime:=DownTime, Procedure:="ShutDown", _
Schedule:=False
End Sub
0
 
LVL 3

Expert Comment

by:Frank White
ID: 37725455
To use Jerseysam's solution, add this code in ThisWorkbook:

Private Sub Workbook_Open()
    'Remove the single-quote at the start of the line below to give a warning to the user.
    'MsgBox "This workbook will auto-close after 20 seconds of inactivity"
    Call SetTime
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call Disable
End Sub


Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    Call Disable
    Call SetTime
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
    Call Disable
    Call SetTime
End Sub


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target _
As Excel.Range)
    Call Disable
    Call SetTime
End Sub

Open in new window

0
 
LVL 21

Expert Comment

by:netcmh
ID: 37729061
Thank you for the grade. Good luck.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question