5,139
社区成员
发帖
与我相关
我的任务
分享
Private Sub Document_Open() '每当打开此文档时就执行...
Dim avar As Variable
Dim abool As Boolean
For Each avar In ActiveDocument.Variables
If avar.Name = "限次" Then
abool = True
avar.Value = avar.Value + 1
Exit For
End If
Next avar
If abool = False Then
ActiveDocument.Variables.Add Name:="限次", Value:=1 '新建文档变量
ElseIf avar.Value > 5 Then
MsgBox "你已经达到了5次,将会关闭"
ActiveDocument.Save
ActiveDocument.Close
End If
ActiveDocument.Save
End Sub