Disabling Macro protection in VBA

J

Jim

Hi,

I've got a macro that runs, opening lots of other project
files. However, some of these files will have macros in
them (because Project 2K adds a macro if you save it as 98
version).

I don't want the window to pop up, asking whether these
macros should be enabled/disabled each time. Instead I
was to lower the macro security while the files are
processed before returning it to Medium.

I've tried the following, using SendKeys but to no avail.
The Sendkeys are not working as I would expect. Any ideas?

Application.MacroSecurity
DoEvents 'does this help?
SendKeys "%L~", True 'send Alt-l to choose Low and
press enter
DoEvents 'does this help?
SendKeys "~", True 'press enter again for good luck?
DoEvents
MsgBox "set macro security"
Application.MacroSecurity
SendKeys "%m", True 'return it to medium
SendKeys "~", True 'press enter
MsgBox "reset"

I also presume that I can hide the Macro security window
by setting Displayalerts - is this correct?

Thanks
Jim
 
J

Jason-W

Hi,

1) From my experience there is no way to programmatically
change the security settings. This is to prevent
malicious code from auto-running when you open a file.

2) Using the SendKeys command is usually not a good idea.
If another application becomes active during execution
then "bad things" can potentially occur depending on what
application takes control.

Is there a particular reason you don't want to just
manually set it to low before running?

Sorry,
--Jason
 
S

Steve Kearon

Reading between the lines on your original query, it sounds like you may be
lucky. I believe Project98 has an application.MacroVirusProtection() method
to enable+disable the setting. This method was removed for Project 2000
(since malicious macros might be fiendishly clever and turn off macro virus
protection)

Steve
 
J

John

Jim,
I think you best bet is user training. I had a similar situation a year
ago and the only solution was to inform users to answer "Enable macros"
the first time they see it. From then on the macros I wrote for them
automatically turned off macro virus protection. And yes, this leaves
their PC vunerable to a macro virus but I believe half of the
responsibility for guarding against viruses is common sense on the users
part (i.e. don't open files from someone you don't know and trust).

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top