Změna nastavení makra na test virů v Excelu

Detaily:
Dvě funkce pro změnu nastavení makra v Excelu 2000 a 97.

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 
Private Const HKEY_CURRENT_USER As Long = &H80000001


Function MacroSecurity2000(lSecurityLevel As Long) As Boolean

   ' Vstup : lSecurityLevel
   ' 1, nastavuje bezpečnost na "Low" (vypnutí hledání virů)
   ' 2, nastavuje bezpečnost na "Medium"
   ' 3, nastavuje bezpečnost na "High"
   ' Výstup : Vrací True pokud bylo nastavení úspěšně změněno

   Dim sData As String, lRet As Long
   Const csPath = "Software\Microsoft\Office\9.0\Excel\Security", 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


Function MacroSecurity97(bDisableVirusChecking As Boolean) As Boolean

   ' Vstup : bDisableVirusChecking 
   ' True, vypne makroochranu
   ' False, zapne ochranu před makroviry
   ' Výstup : Vrací True pokud byla změna úspěšná

   Dim lData As Long, lRet As Long
   Const csPath = "Software\Microsoft\Office\8.0\Excel\Microsoft Excel"
    Const csValue = "Options6"

   On Error GoTo ErrFailed
   If bDisableVirusChecking Then
      lData = 0 
   Else
      lData = 8 
   End If

   RegCreateKey HKEY_CURRENT_USER, csPath, lRet
   RegSetValueEx lRet, csValue, 0, REG_HEX, lData, 4
   RegCloseKey lRet
   MacroSecurity97 = True

   Exit Function

ErrFailed:
   MacroSecurity97 = False

End Function

Zpět

Autor: The Bozena