Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Save and exit automatically

Hi!
I wanted to make a short macro, which saves and closes my exce
workbook automatically when I haven't done any changes within last 1
mins.

The code below shows how to do it, but it also causes som
disfunctions. For example the 'Find' command doesn't work while thi
code is running.

Please give a tip if you know better way to do this or it you know wha
changes I should do to this code to make it work properly.

Thanks!
-AnsiSys

-----Cut here------
Dim Changed As Boolean

Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Source As Range)
Changed = True
End Sub

Private Sub Workbook_Open()
Changed = False
Dim Time1
Dim Time2
Start:
Time1 = Timer: Time2 = Timer
Do Until Time2 - Time1 600 Or Changed = True
DoEvents
Time2 = Timer
Loop
If Changed Then Changed = False: GoTo Start
If Me.Saved = False Then Me.Save
Me.Close
End Sub
-----And here-----

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Save and exit automatically

Use application.OnTime instead:

See Chip Pearson's page on this:

http://www.cpearson.com/excel/ontime.htm

--
Regards,
Tom Ogilvy

"AnsiSys " wrote in message
...
Hi!
I wanted to make a short macro, which saves and closes my excel
workbook automatically when I haven't done any changes within last 10
mins.

The code below shows how to do it, but it also causes some
disfunctions. For example the 'Find' command doesn't work while this
code is running.

Please give a tip if you know better way to do this or it you know what
changes I should do to this code to make it work properly.

Thanks!
-AnsiSys

-----Cut here------
Dim Changed As Boolean

Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Source As Range)
Changed = True
End Sub

Private Sub Workbook_Open()
Changed = False
Dim Time1
Dim Time2
Start:
Time1 = Timer: Time2 = Timer
Do Until Time2 - Time1 600 Or Changed = True
DoEvents
Time2 = Timer
Loop
If Changed Then Changed = False: GoTo Start
If Me.Saved = False Then Me.Save
Me.Close
End Sub
-----And here------


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Save and exit automatically

Hi!

Thanks for the tip! But now I have another problem.
How to close just the active workbook?
------------------------------------------------------
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
'
' The procedure is called by Windows. Put your
' timer-related code here.
'
' -# Both of these lines will close all documents and
' exit Excel #-

ThisWorkbook.Close
ActiveWorkbook.Close

' -# This line doesn't work, because this code has to be
' in module #-

Me.Close

End Sub
------------------------------------------------------

-AnsiSy

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I set up a file to automatically save on exit? Brian Excel Discussion (Misc queries) 1 May 15th 10 04:34 PM
On Exit, always asked to save loveexcel Excel Worksheet Functions 3 June 29th 06 09:51 PM
Save & Exit Anthony Excel Worksheet Functions 1 February 12th 05 05:23 PM
How to Exit Excel Automatically JMPS Excel Programming 2 December 10th 03 04:39 PM
save on exit message box Olly[_3_] Excel Programming 3 November 7th 03 09:32 PM


All times are GMT +1. The time now is 01:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"