Jump to content
emendelson

Set Microsoft Word options?

Recommended Posts

emendelson

I'm trying to write an AutoIt script that will perform various VBS operations in Microsoft Word, and I'm baffled by one thing. I can get the value of a Word option, but I can't figure out how to set that option. Here is a script that opens an old WordPerfect file. I am trying to set an option in Word that disables the "confirm conversion" prompt. I can do this in a VBS script, but can't figure out how to do the same thing in AutoIt. This is as far as I've got:

$word = ObjCreate("Word.Application")
$word.visible = True

$confConversions = $word.Options.ConfirmConversions
If $confConversions = True Then
    $word.Options.ConfirmConversions = False
EndIf

$doc = $word.Documents.open(@ScriptDir & "\test.wp", True)
$doc = $word.ActiveDocument

The variable $confConversions correctly shows the existing state of the ConfirmConversions option, but I can't figure out the syntax that changes that option. The line $word.Options.ConfirmConversions = False seems to do nothing.

I'll be very grateful for any help.

Share this post


Link to post
Share on other sites
water

You could use the Word UDF that comes with AutoIt. Function _Word_DocOpen allows to set the ConfirmConversions property.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
emendelson

This is exactly what I was looking for - and it seems that you wrote the UDF, so double thanks. One more question, which I hope isn't thread drift:

I want my script to run invisibly, and not disturb any existing instances of Word, and then close down the instance of Word that it created. When I run the following script, even if there is no existing instance of Word when it starts, an instance of Word remains running at the end:

#include <Word.au3>
$infile = FileGetShortName(@ScriptDir & "\test.wp")
$outfile = @ScriptDir & "\test1.docx"
$oWord = _Word_Create(False, True)
$secAutomation = $oWord.AutomationSecurity
$oWord.AutomationSecurity = 3
$oDoc = _Word_DocOpen($oWord, $infile, False)
$oDoc = $oWord.ActiveDocument
$oWord.Run("WPtoWordMacro")
_Word_DocSaveAs($oDoc, $outfile, 12)
_Word_DocClose($oDoc)
$oWord.AutomationSecurity = $secAutomation
_Word_Quit

Am I doing something that's obviously wrong? I seem to be able to make the instance of Word close itself if I change the last line to

$oWord.Application.Quit

But I would prefer to use this terrific UDF if possible.

Again, thanks for your help with this already.

Share this post


Link to post
Share on other sites
water

You need to specify which instance of Word should be closed.

_Word_Quit($oWord)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.