Sign in to follow this  
Followers 0
dufran3

Word macro settings using COM

11 posts in this topic

I am trying to change the Microsoft Word macro security settings on Office 2002/XP. I am trying to do this using COM. I looked up some of the doc's and found a few things, but haven't been able to get this working. I am getting no errors in Scite with this. But I check word and the macro security hasn't changed. Help!?

$oWord = ObjCreate('Word.Application.10')
$oWordMacro = $oWord.AutomationSecurity
$oWordMacro = 'msoAutomationSecurityLow'

This is from Microsoft, found this to help with the COM objects. Below is the most relevant part.

http://office.microsoft.com/en-us/orkXP/HA011362661033.aspx

Programming-related security issue

Macro security prior to Office XP was not enabled that is, security was set to Low by Office applications started by an executable program making a call into the application object. Therefore, any macro would run when an application like Word opened a document and instructed it to run a macro, regardless of whether the macro was trusted or not. To address this issue of low security, a new security method was added to all VBA application objects called AutomationSecurity. This method can be used with the application object for each Office application.

Example:

Application.AutomationSecurity=msoAutomationSecurityLow

The values for use with this method are:

* msoAutomationSecurityLow

Sets the macro security to Low for this application; macros run without checking their certificate for authenticity.

* msoAutomationSecurityByUI

Sets the macro security to the same level as currently set in the user interface for the application (as found in the Security dialog).

* msoAutomationSecurityForceDisable

Sets the macro security level to High; all macros must be from a trusted source in order to run.

For programmers who need to instruct Office applications to open files and run macros, it is recommended they set this method to msoAutomationSecurityByUI prior to opening a file to conform to the security level set for the application by the user. For instances where high security is required, use the msoAutomationSecurityForceDisable to disable the running of any macros.

Share this post


Link to post
Share on other sites



Tried this by following the COM/ILE reference. Tried using the same type of thing that was used for the Excel stuff, but didn't work for me.

$oWord = ObjCreate('Word.Application')
$oWord.ApplicationSecurity = 'msoAutomationSecurityLow'

Getting a "The requested action with this object has failed.:" message

Share this post


Link to post
Share on other sites

You may want to take a look at my Word Automation Library (see my signature), I think you will find it very easy to use.

This example should work along with my library mentioned above.

#include <Word.au3>

Const $msoAutomationSecurityByUI = 2
Const $msoAutomationSecurityForceDisable = 3
Const $msoAutomationSecurityLow = 1

$oWordApp = _WordCreate()
$oWordApp.AutomationSecurity = $msoAutomationSecurityLow

Share this post


Link to post
Share on other sites

I used the code you supplied. I get no errors. It opens up a word document. I tried closing then re-opening, and if I go to "Tools>Macro>Security" it is still set to high.

Share this post


Link to post
Share on other sites

See what this writes to the console.

#include <Word.au3>

Const $msoAutomationSecurityByUI = 2
Const $msoAutomationSecurityForceDisable = 3
Const $msoAutomationSecurityLow = 1

$oWordApp = _WordCreate()

With $oWordApp
    $oAS = .AutomationSecurity
    ConsoleWrite($oAS & @CR)
    $oAS = $msoAutomationSecurityLow
    ConsoleWrite($oAS & @CR)
EndWith

Share this post


Link to post
Share on other sites

This is what is in the console after running.

>Running:(3.2.2.0):C:\Program Files\AutoIt3\autoit3.exe "H:\AutoIt\Example Scripts\Using COM\Word COM test.au3"

1

1

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 2.743

Share this post


Link to post
Share on other sites

Do you have any idea what is going on here?

Share this post


Link to post
Share on other sites

Anything anyone? I tried looking up MSDN stuff, but couldn't find anything. I'm not sure why this isn't working. This sets the option permanently? Not just for the current document right?

Share this post


Link to post
Share on other sites

Can someone please help me with this. This is the last piece that isn't working that I need. I still have been unable to get it working.

Share this post


Link to post
Share on other sites

Sorry for the late reply, I haven't been around much the last few days.

First of all what environment are you testing this with?

When I get a chance I'll dig into it and see what I can figure out.

Share this post


Link to post
Share on other sites

I'm on Win XP SP2. nothing out of the ordinary. Using Microsoft Office XP/2002 with SP3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0