我遇到多个用户需要访问工作簿的情况(由于所有问题,我们希望避免使用' Share Workbook'选项)。我已经确定一个可能的解决方案是让工作簿在15分钟不活动后自动关闭。
我还希望在15分钟后弹出一条消息,提醒用户,除非他们点击“好的”'按钮,工作簿将关闭。如果他们点击按钮,我希望计数器重新开始,理想情况下,如果他们不点击任何内容,工作簿将在1分钟后自动关闭。
我在网上找到了一些我用过的代码。工作簿在指定时间后成功关闭,但我无法弄清楚如何弹出消息框。非常感谢任何帮助,谢谢!
我使用的代码如下:
在模块1中:
func update(_ seconds: TimeInterval) {
accumulatedSeconds += seconds
// `poseDuration` is `animationDuration / 6`.
guard accumulatedSeconds >= poseDuration else { return }
switch currentFrame {
case 6:
myView.layer.contentsRect = CGRect(x: 0, y: 0, width: width, height: 1)
currentFrame = 1
default:
myView.layer.contentsRect = CGRect(x: width * Double(currentFrame), y: 0, width: width, height: 1)
currentFrame += 1
}
accumulatedSeconds -= poseDuration
}
在ThisWorkbook中:
Dim DownTime As Date
Sub SetTimer()
DownTime = Now + TimeValue("0:15:00")
Application.OnTime EarliestTime:=DownTime, _
Procedure = "ShutDown", Schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown", Schedule:=False
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
With ThisWorkbook
.Saved = True
.Close
End With
End Sub
答案 0 :(得分:0)
尝试以下ShutDown
程序:
Sub ShutDown()
If CreateObject("WScript.Shell").PopUp("Close Excel?", 60, "Excel", vbOKCancel + vbQuestion + vbSystemModal) = vbCancel Then
StopTimer
SetTimer
Exit Sub
End If
Application.DisplayAlerts = False
With ThisWorkbook
.Saved = True
.Close
End With
End Sub
答案 1 :(得分:0)
永远不要与同事共享网络驱动器上的Excel文件。您将遇到各种问题,包括工作簿损坏和其他问题。尝试使用此脚本,在n分钟不活动后自动关闭Excel文件。
首先,将以下代码添加到标准宏模块。请注意,有三个例程要添加: Dim DownTime As Date
var app = angular.module('plunker', []);
app.directive("mydir" , ['$compile', '$templateRequest', function($compile, $templateRequest){
return {
scope : {
items: "=mydir"
},
compile: function($element) {
var transclude = $element.html();
$element.html('');
return function(scope, elem) {
$templateRequest("template.html").then(function(html){
var tpl = angular.element(html);
tpl.children('.transclude').append(transclude);
$compile(tpl)(scope);
elem.append(tpl);
});
};
}
};
}]);
app.controller('MainCtrl', function($scope) {
$scope.items = [{
name: "Item 1"
},{
name: "Item 2"
}]
});
需要将下一个例程(其中有四个)添加到ThisWorkbook对象中。打开VBA编辑器,在Project Explorer中双击ThisWorkbook对象。在Excel打开的代码窗口中,放置以下例程:
Sub SetTimer()
DownTime = Now + TimeValue("01:00:00")
Application.OnTime EarliestTime:=DownTime, _
Procedure = "ShutDown", Schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown", Schedule:=False
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
With ThisWorkbook
.Saved = True
.Close
End With
End Sub
查看所有信息。
http://excelribbon.tips.net/T008192_Forcing_a_Workbook_to_Close_after_Inactivity.html