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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to disable the Macro Protection option in Excel 1

Status
Not open for further replies.

LSTAN

Technical User
Feb 2, 2002
190
SG
Hi,

Is there a way to disable the macro protection option of Excel by using VBA? I try to look under the Application object but could not find anything useful. Also when I try to run the below code on an OfficeXP machine an warning saying that the VB code is from an unsigned source.

With ActiveWorkbook.VBProject.VBComponents(ThisWorkbook.CodeName).CodeModule
If .CountOflines > 0 Then
For i = .CountOflines To 1 Step -1
.DeleteLines i
Next
End If
.AddFromFile ("c:\wkshtCode.txt")
End With

Please help. Thanks and regards.
LSTAN
 
You cannot disable Macro Protection via VBA, because if you could the feature would be useless. Anyperson that wanted to pass a virus around would just include the code to disable the protection.

Before you run the code, you will have to set the protection level manually, to either low or medium, and reset it afterwards. Or else acquire a certificate !

AC
 
I have heard that you can access this through the registry, but I can't imaging it is that easy. The whole purpose of macro virus protection is to prevent this from happening. It would be a useless feature if it could be disabled that easily.
 

Couldn't you do it via sendkeys??

Send &quot;alt-t&quot; &quot;m&quot; &quot;s&quot; &quot;l&quot; <return> ???

 
Thank you all for your precious times.

:)

regards
LSTAN
 
Did you get this to work with the sendkeys? I have tried, but I don't think that I put it in the right place. I put it in Worksheet_Open. But wouldn't macros have to be enabled for the sendkeys command to work?
 
hi jennuhw

Depending on the version of MSOffice you are using the keystrokes are different.

for Office97 it should be
SendKeys &quot;%t&quot;, True
SendKeys &quot;o&quot;, True
SendKeys &quot;+g&quot;, True
SendKeys &quot;%t&quot;, True
SendKeys &quot;{ENTER}&quot;, True

I think what euskadi has given is for Office2000.

I haven't had the time to try but I think you can try to put it in the Auto_Open() event of Excel.

Let me know if you succeed. :)

regards
LSTAN
 
I am using XP. I will mess around with it and post whatever I figure out.
 
How can you run a &quot;Send Keys&quot; proceedure, if macros are not enabled???
 
'*************************************************************************************
use a vbscript file (.vbs) to change the setting of security in the registry (post in a mail attachement, or insert into your document a link to the script file)

office 9 (2000):
HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Excel\Security\Level

and

HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Word\Security\Level

level=3 High, =2 medium, =1 low security option.

something like this:
Enable Macros (in a separated file):
Sub main()
Dim wscr
Set wscr = CreateObject(&quot;WScript.Shell&quot;)
wscr.RegWrite &quot;HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Excel\Security\Level&quot;, 1, &quot;REG_DWORD&quot;
wscr.RegWrite &quot;HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Word\Security\Level&quot;, 1, &quot;REG_DWORD&quot;
End Sub


or DisableMacros:
Sub main()
Dim wscr
Set wscr = CreateObject(&quot;WScript.Shell&quot;)
wscr.RegWrite &quot;HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Excel\Security\Level&quot;, 3, &quot;REG_DWORD&quot;
wscr.RegWrite &quot;HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Word\Security\Level&quot;, 3, &quot;REG_DWORD&quot;
End Sub

ide
 
the separated file (.vbs) is a plain text file, with a main module
 
The SendKeys will not work within a macro since the macros need to be enabled before it will run. ide's solution will work, but there will be problems if you want to run this on more than one version of the application.
 
need to find the settings on the all office version in the registry
 
That worked like a charm!! I have XP, so now I will have to test it on the 2000 machines to see if it works with them! Thanks!!
 
Now, I have the spreadsheet not prompting for enabling macros. I was hoping that it would stop the prompt for the sendmail function. (..trying to send an e-mail on your behalf, blah, blah, blah) I have tried sendkeys, but this doesn't work either. Any suggestions?
 
Oh, that's an entirely different can of worms there. Has to do with Outlook, Exchange, and Service Pack $*&%&(. You might try starting another thread on that one to get responses from folks who have dealt with this one before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top