Disable Word Macro Access

Hi all,

When using Office 2000 + XP I can call and run a macro inside Visual Basic Editor using:

vlines := wordApp.VBE.ActiveVBProject.VBComponents.Item(1).CodeModule.CountOfLines;

But when using Office 2007 + Vista it raises a exception stating that "The programming access to visual basic project isn't reliable". I tried changing the macro access setup but it doesn't work.

Any tip?

Thkx all
paulo_psaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

paul_djCommented:
I think you may need to check a setting in 2007..

Click the Office button (top left corner) -> Word Options -> Trust Center -> Trust Center Settings -> check thte box labeled 'Trust access to the VBA project model'.  Click OK twice to close Word Options.
paulo_psaAuthor Commented:
Hi paul_dj,

I already tried this option and it didn't work.
Maybe I need to make registry changes but I don't know how.

thkx


paulo_psaAuthor Commented:
Hi paul_dj,

Dealing with your suggestion I note that it works when I uncheck/check the box 'Trust access to the VBA project model' before call the procedure. So I need to do it every time. I just need now to know how to make this changes permanent.

regards
paul_djCommented:
When you check the box in Word Options, it *should* stay that way for the current user.  The following registry key is where the trust access value is stored (1 = trust, 0 = unchecked):

HKCU\Software\Microsoft\Office\12.0\Word\Security\AccessVBOM

Maybe you can write to that reg key at the beginning of your code to ensure it's set to 1?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paulo_psaAuthor Commented:
You're right the only way to do that is setting the registry. I'm not sure if it's a good idea to keep making changes in clients machines programmaticaly.
Anyway thanks it's clear now.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.