1、1制作 Excel“自杀” 文件2010 年 7 月 25 日 整理一:打开立即“自杀”步骤 1:新建一个 Excel 表格。步骤 2:点“工具”“宏”“Vistual Basic 编辑器”(如下图所示)。或用快捷键“Alt+F11”步骤 3:在弹出的窗口中,双击:ThisWorkbook步骤 4:在弹出的窗口中输入以下代码,保存后即可。Sub KillThisWorkBook()With ThisWorkbook.Saved = True.ChangeFileAccess xlReadOnlyKill .FullName.CloseEnd WithEnd SubPrivate Sub Wor
2、kbook_Open()Call KillThisWorkBookEnd Sub2二:限制次数打开“自杀” ( 注:此方法制作的文件,每次打开后要手动保存,打开次数才会增加!)步骤 1:新建一个 Excel 表格,步骤 2:点“工具”“宏”“Vistual Basic 编辑器”(如下图所示)。或用快捷键“Alt+F11”步骤 3:在弹出的窗口中,双击:ThisWorkbook步骤 4:在弹出的窗口中输入以下代码,把光标指到 AddHiddenNames()区域,按F5 运行代码, ,建立 OpenTimes 变量。 (建立 OpenTimes 变量方法二:在 Excel 菜单中点“插入”“名称
3、”“自定义” ,输入 OpenTimes,把引用位置中输入=0,如下所示)。保存,退出即可。注:修改如下代码中红色数字,即可改变打开限制次数。Option ExplicitSub HideNames()ThisWorkbook.Names(“Opentimes“).Visible = TrueEnd SubSub AddHiddenNames()ThisWorkbook.Names.Add Name:=“OpenTimes“, _RefersTo:=“=0“, Visible:=FalseEnd SubSub ReadOpenTimes()Dim OTimes As IntegerOTimes
4、 = Evaluate(ThisWorkbook.Names(“OpenTimes“).RefersTo)OTimes = OTimes + 1If OTimes 10 ThenCall KillThisWorkBookElseThisWorkbook.Names(“OpenTimes“).RefersTo = “=“ & OTimesEnd If3End SubSub KillThisWorkBook()With ThisWorkbook.Saved = True.ChangeFileAccess xlReadOnlyKill .FullName.CloseEnd WithEnd SubPr
5、ivate Sub Workbook_Open()Call ReadOpenTimesEnd Sub三:限制次数打开“自杀” ( 注:此方法制作的文件,每次打开后会自动保存,打开次数会自动增加!)步骤 1:新建一个 Excel 表格,步骤 2:点“文件”“属性”“自定义” ,在名称一栏中输入“OpenTimes”在类型中选“数字” ,在取值中写入“0”,点“更改” ,如下所示。步骤 3:点“工具”“宏”“Vistual Basic 编辑器”(如下图所示)。或用快捷键“Alt+F11”步骤 4:在弹出的窗口中,双击:ThisWorkbook步骤 5:在弹出的窗口中输入以下代码,保存退出即可。注:
6、修改如下代码中红色数字,即可改变打开限制次数。Option ExplicitSub ReadOpenTimes()Dim Opentimes As IntegerWith Me4Opentimes = .CustomDocumentProperties(“OpenTimes“).Value + 1If Opentimes 10 ThenCall KillThisWorkBookElse.CustomDocumentProperties(“OpenTimes“).Value = Opentimes.SaveEnd IfEnd WithEnd SubSub KillThisWorkBook()Wi
7、th ThisWorkbook.Saved = True.ChangeFileAccess xlReadOnlyKill .FullName.CloseEnd WithEnd SubPrivate Sub Workbook_Open()Call ReadOpenTimesEnd Sub四:限制次数打开“自杀” 。步骤:直接在 ThisWorkbook 中输入以下代码(说明:k = 4,限用三次,第 4 次自杀):Private Sub Workbook_Open()Application.DisplayAlerts = Falsek = GetSetting(appname:=“MyApp“,
8、 section:=“Startup“, Key:=“aaa“, Default:=1)If k = 4 ThenActiveWorkbook.ChangeFileAccess xlReadOnlyKill ActiveWorkbook.FullNameThisWorkbook.Close FalseEnd Ifk = k + 1SaveSetting “MyApp“, “Startup“, “aaa“, kEnd Sub五:定时“自杀”步骤:直接在 ThisWorkbook 中输入以下代码:(注:红色部分为定时时间)Private Sub Workbook_Open()If Now() = DateSerial(“2010“, “7“, “24“) Then5ActiveWorkbook.ChangeFileAccess xlReadOnlyKill ActiveWorkbook.FullNameApplication.QuitEnd IfEnd Sub