VBA實(shí)現(xiàn)用戶(hù)每月只能使用3次的功能

Private Sub Workbook_active()
??'讀取上次打開(kāi)日期
??Dim lastOpenDate As Date
??lastOpenDate = Range("A1").Value
???
??'如果是新月份,則重置打開(kāi)次數(shù)
??If Month(Date) <> Month(lastOpenDate) Then
????Range("B1").Value = 0
??End If
???
??'增加打開(kāi)次數(shù)
??Range("B1").Value = Range("B1").Value + 1
???
??'更新打開(kāi)日期
??Range("A1").Value = Date
???
??'如果超過(guò)了三次,則關(guān)閉工作簿
??If Range("B1").Value > 3 Then
????MsgBox "本月已經(jīng)超過(guò)了三次打開(kāi)記錄工作簿的限制。"
????ThisWorkbook.Close savechanges:=False
??End If
End Sub
Private Sub Workbook_AfterSave(ByVal Succes As Boolean)
Excel.Application.Quit
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Activeworkbook.Save
End Sub
標(biāo)簽: