|
本帖最后由 liucqa 于 2012-2-14 15:16 编辑
zhyj_88 发表于 2012-2-14 14:59
你的信任代码中 .SendKeys "%tms{tab}{tab}v~"
在tms后打开时有t,而取消时无t ,经验证无t也可以正常操作 ...
Alt-t m s 是2003的打开信任窗口的快捷键,后面那个t没用,估计是输入错误
我的代码应该都有t吧
Private Sub Workbook_Open()
'打开“信任对VBA工程对象模型的访问”
If Not SecuritySet(ThisWorkbook) Then MsgBox "本程序将打开“信任对VBA工程对象模型的访问”"
Do Until SecuritySet(ThisWorkbook)
With Application
If CDbl(Val(Application.Version)) <= 11 Then
MsgBox "本程序只支持Excel2007以上版本"
End
Else
.SendKeys "%tms{tab}{tab}v~"
'.SendKeys "%las{tab}e{tab}v~"
End If
.CommandBars.FindControl(ID:=3627).Execute
End With
Loop
End Sub
Private Sub Workbook_beforeclose(cancel As Boolean)
'取消“信任对VBA工程对象模型的访问”
If SecuritySet(ThisWorkbook) Then
Application.OnTime earliesttime:=Now + TimeSerial(0, 0, 1), procedure:="quitapp", schedule:=True
Application.SendKeys "%tms{tab}{tab}v~", True
cancel = True
End If
Exit Sub
End Sub |
|