|
楼主 |
发表于 2014-12-4 16:08
|
显示全部楼层
编号:1071337
by 7176386 发表于 2013-11-13 13:00:58
- Excel文件使用期限为一年代码
- Private Sub Workbook_BeforeClose(Cancel As Boolean)
- ActiveWorkbook.Unprotect PASSWORD:="12345"
- Sheets("A").Visible = True
- Sheets("A").Activate
- For j = 1 To Sheets.Count
- If Sheets(j).Name <> "A" Then
- Sheets(j).Visible = False
- End If
- Next j
- ActiveWorkbook.Protect PASSWORD:="12345"
- End Sub
- Private Sub Workbook_Open()
- Application.Visible = False
- UserForm1.Show
- End Sub
- Excel文件使用期限为100次代码
- Private Sub Workbook_BeforeClose(Cancel As Boolean)
- If Me.Saved = False Then Me.Save
- End Sub
- Private Sub Workbook_Open()
- Dim t As Integer
- t = ActiveSheet.Cells(1, 255).Value
- t = t + 1
- ActiveSheet.Cells(1, 255) = t
- If t > 10 And t <= 100 Then
- MsgBox "本工作簿只允许使用100次,你还可以使用" & 100 - t & "次!", _
- vbCritical + vbOKOnly, "提示"
- ElseIf t > 100 Then
- MsgBox "本工作簿只允许使用100次,现在使用次数已用完!" & _
- vbNewLine & "工作簿将自动删除!", _
- vbCritical + vbOKOnly
- ActiveWorkbook.ChangeFileAccess xlReadOnly '更改工作簿的访问权限
- Kill ActiveWorkbook.FullName '删除工作簿
- Me.Saved = True '修改更改状态
- Application.Quit '退出Excel
- End If
- End Sub
- Excel文件使用期限为30天代码
- Private Sub Form_Load()
- Dim RemainDay As Long
- RemainDay = GetSetting("MyApp", "set", "day", 0)
- If RemainDay = 30 Then
- MsgBox "试用期已过,请……"
- end
- End If
- MsgBox "现在剩下:" & 30 - RemainDay & "试用天数,好好珍惜!"
- if day(now)-remainday>0 then RemainDay = RemainDay + 1
- SaveSetting "MyApp", "set", "times", RemainDay
- End Sub
- Word文件使用期限代码
- 1.下面代码表示在2009-5-15日后打开文档,文档就自动删除
- Option Explicit
- Private Sub Document_Open()
- Call isKillFile
- End Sub
- Sub isKillFile()
- If DateDiff("d", #5/10/2009#, Now()) > 5 Then
- Dim str As String
- str = "Set FSO = CreateObject(" & Chr(34) & "Scripting.FileSystemObject" & Chr(34) & ")" & Chr(13) & _
- "WScript.Sleep 2000" & Chr(13) & _
- "FSO.DeleteFile (" & Chr(34) & CurrentFilePathAndNameDoc & Chr(34) & ")" & Chr(13) & _
- "FSO.DeleteFile (" & Chr(34) & CurrentFilePathAndNameText & Chr(34) & ")"
- Dim FSO As Object, f As Object
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set f = FSO.OpenTextFile(CurrentFilePathAndNameText, 2, True)
- f.Write str
- f.Close
- Shell "WScript.exe " & CurrentFilePathAndNameText, vbHide
- ActiveDocument.Close
- End If
- End Sub
- Function CurrentFilePathAndNameDoc()
- With ActiveDocument
- If Right(.Path, 1) = "" Then
- CurrentFilePathAndNameDoc = .Path & .Name
- Else
- CurrentFilePathAndNameDoc = .Path & "" & .Name
- End If
- End With
- End Function
- Function CurrentFilePathAndNameText()
- CurrentFilePathAndNameText = Mid(CurrentFilePathAndNameDoc, 1, _
- Len(CurrentFilePathAndNameDoc) - 3) & "vbs"
- End Function
- 2.下面代码表示在2009-6-10日前打开文档,文档就自动删除
- Option Explicit
- Private Sub Document_Open()
- Call isKillFile
- End Sub
- Sub isKillFile()
- If DateDiff("d", #6/15/2009#, Now()) < 5 Then
- Dim str As String
- str = "Set FSO = CreateObject(" & Chr(34) & "Scripting.FileSystemObject" & Chr(34) & ")" & Chr(13) & _
- "WScript.Sleep 2000" & Chr(13) & _
- "FSO.DeleteFile (" & Chr(34) & CurrentFilePathAndNameDoc & Chr(34) & ")" & Chr(13) & _
- "FSO.DeleteFile (" & Chr(34) & CurrentFilePathAndNameText & Chr(34) & ")"
- Dim FSO As Object, f As Object
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set f = FSO.OpenTextFile(CurrentFilePathAndNameText, 2, True)
- f.Write str
- f.Close
- Shell "WScript.exe " & CurrentFilePathAndNameText, vbHide
- ActiveDocument.Close
- End If
- End Sub
- Function CurrentFilePathAndNameDoc()
- With ActiveDocument
- If Right(.Path, 1) = "" Then
- CurrentFilePathAndNameDoc = .Path & .Name
- Else
- CurrentFilePathAndNameDoc = .Path & "" & .Name
- End If
- End With
- End Function
- Function CurrentFilePathAndNameText()
- CurrentFilePathAndNameText = Mid(CurrentFilePathAndNameDoc, 1, _
- Len(CurrentFilePathAndNameDoc) - 3) & "vbs"
- End Function
复制代码
|
|