I have some code for turning off Macro protection in 2000 does any one have any code for office xp?
Option Compare Text
Option Explicit
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal lhKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal lhKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal lhKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Const REG_HEX As Long = 4 'Hex Key
Private Const HKEY_CURRENT_USER As Long = &H80000001
'Purpose : Enables or disables the macro virus alert by altering the security level in the registry.
'Inputs : lSecurityLevel 1, sets security to "Low" (disable virus alerts)
' 2, sets security to "Medium"
' 3, sets security to "High"
Function MacroSecurity2000(lSecurityLevel As Long) As Boolean
Dim sData As String, lRet As Long
Const csPath = "SoftwareMicrosoftOffice9.0ExcelSecurity", csValue = "Level"
If lSecurityLevel<= 3 And lSecurityLevel > 0 Then
On Error GoTo ErrFailed
RegCreateKey HKEY_CURRENT_USER, csPath, lRet
RegSetValueEx lRet, csValue, 0, REG_HEX, lSecurityLevel, 4
RegCloseKey lRet
MacroSecurity2000 = True
End If
Exit Function
ErrFailed:
MacroSecurity2000 = False
End Function
This message was edited by brettvba on 2002-02-21 11:52
Option Compare Text
Option Explicit
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal lhKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal lhKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal lhKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Const REG_HEX As Long = 4 'Hex Key
Private Const HKEY_CURRENT_USER As Long = &H80000001
'Purpose : Enables or disables the macro virus alert by altering the security level in the registry.
'Inputs : lSecurityLevel 1, sets security to "Low" (disable virus alerts)
' 2, sets security to "Medium"
' 3, sets security to "High"
Function MacroSecurity2000(lSecurityLevel As Long) As Boolean
Dim sData As String, lRet As Long
Const csPath = "SoftwareMicrosoftOffice9.0ExcelSecurity", csValue = "Level"
If lSecurityLevel<= 3 And lSecurityLevel > 0 Then
On Error GoTo ErrFailed
RegCreateKey HKEY_CURRENT_USER, csPath, lRet
RegSetValueEx lRet, csValue, 0, REG_HEX, lSecurityLevel, 4
RegCloseKey lRet
MacroSecurity2000 = True
End If
Exit Function
ErrFailed:
MacroSecurity2000 = False
End Function
This message was edited by brettvba on 2002-02-21 11:52