Jump to content

Recommended Posts

Posted

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.

Posted (edited)

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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.

Posted

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

_Word_Quit($oWord)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
  • Recently Browsing   0 members

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