宏将保存并退出Excel文件 [英] Macro which which will save and exit the Excel file

查看:321
本文介绍了宏将保存并退出Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是VBA的新手,需要你的帮助。

I am new to VBA and need your help.

我想要一个可以保存和关闭的宏excel文件一旦空闲。

I want a macro which will save and close the excel file once it is idle.

如果任何单元格处于编辑模式并且光标在单元格中闪烁,那么它也应该保存并关闭它。

If any cell is in editing mode and cursor is blinking in the cell in that case it should also save and close it.

请指教。

Umeed4u

推荐答案

这是一种在不活动20分钟后保存并关闭工作簿的方法。 

Here is a way to save and close your workbook after 20 minutes of inactivity. 

将此代码放入模块中。

'You can close a workbook after some set amount of time of no activity.
'Put this code into a regular codemodule:

Public RunTime As Date

Sub SaveAndCloseMe()
Application.DisplayAlerts = False
ThisWorkbook.Close True
Application.DisplayAlerts = True
End Sub


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.OnTime RunTime, "SaveAndCloseMe", , False
RunTime = Now() + TimeValue("00:20:00")
Application.OnTime RunTime, "SaveAndCloseMe"
End Sub

'It will save and close the workbook after it hasn't been changed for 20 minutes.

将此代码放入'ThisWorkbook'。

Put this code into 'ThisWorkbook'.

'And put this code into the ThisWorkbook object's codemodule - change the 00:20:00
'to how long you want to allow no activity prior to closing the workbook:

Private Sub Workbook_Open()
RunTime = Now() + TimeValue("00:20:00")
Application.OnTime RunTime, "SaveAndCloseMe"
End Sub


这篇关于宏将保存并退出Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆