Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable Macros when accidentally Disabled

Status
Not open for further replies.

cawash

Technical User
Jul 11, 2002
2
0
0
US
I accidentally disabled the macros of a worksheet and could not get them to work. I also found that all of my other worksheets had their macros disabled as well.

I checked secruity and all were on Medium. I checked help and could find nothing that could help me.

help if someone can.

TIA
 
I'm not sure but try this.....

Tools/Options/General/
uncheck macro virus detection Thank you,
Dave Rattigan
 
Also the following code demostrates how to turn on/off Excel's macro virus protection for both Excel 2000 and 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 '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"
'Outputs : Returns True on success
'Author : Andrew Baker ('Date : 25/11/2000 03:33
'Notes : Requires Excel 2000
'Revisions :

Function MacroSecurity2000(lSecurityLevel As Long) As Boolean
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


'Purpose : Enables or disables the macro virus alert.
'Inputs : bDisableVirusChecking True, disables macro security protection
' False, enables macro security protection
'Outputs : Returns True on success
'Author : Andrew Baker ('Date : 25/11/2000 03:33
'Notes : Requires Excel 97
'Revisions :

Function MacroSecurity97(bDisableVirusChecking As Boolean) As Boolean
Dim lData As Long, lRet As Long
Const csPath = &quot;Software\Microsoft\Office\8.0\Excel\Microsoft Excel&quot;, csValue = &quot;Options6&quot;

On Error GoTo ErrFailed
If bDisableVirusChecking Then
lData = 0 'Disabled
Else
lData = 8 'Enabled
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 Thank you,
Dave Rattigan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top