下面的代码我想放到指定的工作表里头,即点击代码所在工作表才生效,并不是打开工作薄就生效,代码该如何修改才是? Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Private Sub Workbook_Open() Dim lngRet As Long Dim strBuffer As String, strTempPath As String strBuffer = String$(260, 0) lngRet = GetTempPath(Len(strBuffer), strBuffer) LNPATH = lngRet If lngRet = 0 Then Exit Sub strTempPath = Left$(strBuffer, lngRet) ThisPath = Mid(ThisWorkbook.FullName, 1, LNPATH) If ThisPath = strTempPath Then MsgBox "禁止从压缩文件中运行本程序!" & vbLf & vbLf & " 请将本文件解压缩后再运行!" ThisWorkbook.Close False End If MsgBox "10秒钟后将删除本程序中的所有代码", , "XQ1234警告:" Application.OnTime Now + TimeValue("00:00:10"), "BkpFilAndDel" End Sub |