MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Feb 21st, 2002, 12:52 PM   #1
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

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 ]
brettvba is offline   Reply With Quote
Old Jun 18th, 2002, 11:15 PM   #2
carolannedlg
New Member
 
Join Date: May 2002
Location: Carol Maas
Posts: 20
Default

Does this change the Security Level as though the user was doing it manually? I didn't think that was possible through VBA code. Does this mean you could change the users settings to Low Security so that it would automatically enable macros?

Thx.
carolannedlg is offline   Reply With Quote
Old Jun 18th, 2002, 11:58 PM   #3
Qroozn
Board Regular
 
Join Date: Mar 2002
Location: Sydney/Brisbane , Australia
Posts: 539
Default

BrettVBA. have you been keeping this a neat little secret ?

does it work in excel 97? or is there something similar?
Qroozn is offline   Reply With Quote
Old Jun 19th, 2002, 12:28 AM   #4
Mo~yu
New Member
 
Join Date: Jun 2002
Posts: 3
Default

One problem buddy boy.
The user will need to disable macros protection in order to run your code to disable macros protection. DUH!
Mo~yu is offline   Reply With Quote
Old Jun 19th, 2002, 03:28 AM   #5
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-06-18 22:58, Qroozn wrote:
BrettVBA. have you been keeping this a neat little secret ?

does it work in excel 97? or is there something similar?
No, it won't work in excel97...the Regestration key and the Bit to change are different.
__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old Jun 19th, 2002, 03:29 AM   #6
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-06-18 23:28, Mo~yu wrote:
One problem buddy boy.
The user will need to disable macros protection in order to run your code to disable macros protection. DUH!
You can overcome this in a number of ways.
__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old Jun 19th, 2002, 02:16 PM   #7
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

This is the code for XP
and your right its not made to hack ppls computers so that they can't choose if they want macros enabled its just a useful piece of code!

I can lookup my 97 ver if you need it!

Rgds Brett

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


Function MacroSecurity2002(lSecurityLevel As Long) As Boolean
Dim sData As String, lRet As Long
Const csPath = "SoftwareMicrosoftOffice10.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
MacroSecurity2002 = True
End If

Exit Function
ErrFailed:
MacroSecurity2002 = False
End Function

Sub changeit()
MacroSecurity2002 (1) 'changes to low
'Also note that 1,2 or 3 can be used low, medium and high security!
End Sub


[ This Message was edited by: brettvba on 2002-06-19 13:26 ]
brettvba is offline   Reply With Quote
Old Jun 19th, 2002, 02:21 PM   #8
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

This should do it for 97 untested as I don't have 97

Regards Brett

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
Function MacroSecurity97(bDisableVirusChecking As Boolean) As Boolean
Dim lData As Long, lRet As Long
Const csPath = "SoftwareMicrosoftOffice8.0ExcelMicrosoft Excel", csValue = "Options6"

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

Sub Change97()
MacroSecurity97 (True)
End Sub

_________________



[ This Message was edited by: brettvba on 2002-06-19 13:23 ]
brettvba is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 01:52 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes