How do I know if macros are enabled?

P

pareshtrivedi

How do I find out from VB code if the word application is going to
allow running macros? Is there any property I can check whether macros
are enabled or not?

Dim lword_app As Word.Application
Dim lword_document As Word.Document

Set lword_app = CreateObject("word.application")
lword_app.AutomationSecurity = msoAutomationSecurityByUI
Set lword_document = lword_app.Documents.Open("D:\test.doc",
Visible=True)

' need something like this
' if lword_document.macro_enabled =True then
' currently getting error here if macros are disabled
lword_app.Run ("test_macro")
 
K

Karl E. Peterson

Can you give straight answer to this?

I'm sorry, but it sounds like you're asking how a program can know whether it's
running. "I think, therefore I am?" Maybe I misunderstand?
 
P

pareshtrivedi

All I am saying is I am opening the word document and then checking if
user has enabled running the macro or not. User may get Security
warning saying 'Macros are disabled for this document...'.
After document is opened I need to programmatically run my macro (which
is part of the template).

If I run the macro without checking if user has enabled or disabled
macros then I get the system error. That's why I want to first check if
the macros are enabled or not using some word property.

Set lword_document = lword_app.Documents.Open("D:\t­est.doc",
Visible=True)

lword_app.Run ("test_macro") 'get the error here if the macros are
disabled.
 
C

Chirag

I think he is running a standalone VB app that automates Word and wants to
run a macro in a document from the standalone VB app.

- Chirag
 
P

pareshtrivedi

Yes I am trying to open the word document from my VB application.
Thanks for clearing out the confusion that Karl had!
 
T

Tushar Mehta

Check out the Application object's AutomationSecurity property.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2005
 
K

Karl E. Peterson

Chirag said:
I think he is running a standalone VB app that automates Word and
wants to run a macro in a document from the standalone VB app.

Ahhhhhhhhhh!!! That makes so much more sense.

That said, I still don't know the answer. ;-0

Thanks... Karl
 

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