Jump to content

Word macro settings using COM


dufran3
 Share

Recommended Posts

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.

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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
Link to comment
Share on other sites

  • Moderators

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...