限制工作簿的使用次数,超过次数就自我删除,也不失为保护作品的一种好方法。但这种方法需要修改注册表。
代码如下:
Private Sub Workbook_Open()
Dim counter As Long, term As Long, chk
chk = GetSetting("hhh", "budget", "使用次数", "")
If chk = "" Then
term = 50 ' 限制使用50次
MsgBox "本工作簿只能使用" & term & "次" & vbCrLf & "超过次数将自动销毁!", vbExclamation
SaveSetting "hhh", "budget", "使用次数", term
Else
ounter = Val(chk) - 1
MsgBox "你还能使用" & counter & "次,请及时注册!", vbExclamation
SaveSetting "hhh", "budget", "使用次数", counter
If counter <= 0 Then
DeleteSetting "hhh", "budget", "使用次数"
killme
End If
End If
End Sub
Public Sub killme()
Application.DisplayAlerts = False
ActiveWorkbook.ChangeFileAccess xlReadOnly
Kill ActiveWorkbook.FullName
ThisWorkbook.Close False
End Sub
将上述程序复制到工作簿的ThisWorkbook对象模块中,保存文件即可。