欢迎光临散文网 会员登陆 & 注册

VBA实现用户每月只能使用3次的功能

2023-03-27 10:47 作者:积硅步志千里  | 我要投稿

Private Sub Workbook_active()

  '读取上次打开日期

  Dim lastOpenDate As Date

  lastOpenDate = Range("A1").Value

   

  '如果是新月份,则重置打开次数

  If Month(Date) <> Month(lastOpenDate) Then

    Range("B1").Value = 0

  End If

   

  '增加打开次数

  Range("B1").Value = Range("B1").Value + 1

   

  '更新打开日期

  Range("A1").Value = Date

   

  '如果超过了三次,则关闭工作簿

  If Range("B1").Value > 3 Then

    MsgBox "本月已经超过了三次打开记录工作簿的限制。"

    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


VBA实现用户每月只能使用3次的功能的评论 (共 条)

分享到微博请遵守国家法律