|
For your reference.
Public Function VBAccessAllowed()
'---------------------------------------------------------------------
' Functoion : Test VBA security settings to see if we can modify
' VBA code (caused by A new security setting in
' Excel 2002: Trust access to Visual Basic Project
' Synopsis: If Version >= 10
' Try and set an object to a workbook project and
' test whether it works or not.
' If fail, show messgae and return False.
' Returns: True/False - default True
'---------------------------------------------------------------------
Dim VBProject As Object ' as VBProject
VBAccessAllowed = True
If Val(Application.Version) >= 10 Then
On Error Resume Next
Set VBProject = ActiveWorkbook.VBProject
If Err.Number <> 0 Then
VBAccessAllowed = False
End If
End If
End Function
'写注册表,创建子键 HKEY_CURRENT_USER\Software\QDE\Defaults\Language
Sub RegWrite()
Dim SA, SB As String
SA = "HKCU\Software\QDE\Defaults\Language\"
SB = "REG_SZ"
RegistryKeyWrite SA, 888, SB
End Sub
'读注册表
Sub RegReader()
Dim SA As String
Dim Owsh
Dim OB
SA = "HKCU\Software\QDE\Defaults\Language\"
Set Owsh = CreateObject("WScript.Shell")
MsgBox Owsh.RegRead(SA)
End Sub
Public Function RegistryKeyWrite(ByVal KeyName As String, ByVal KeyValue, ByVal KeyType As String)
Dim Owsh
Set Owsh = CreateObject("WScript.Shell")
Owsh.RegWrite KeyName, KeyValue, KeyType
On Error GoTo 0
RegistryKeyWrite = Err.Number = 0
If Not RegistryKeyWrite Then
MsgBox "Failed to Write REG.", vbInformation
End If
End Function |
|