Jump to content
fred_beaucamp

Save a doc file after executing a macro in .docx format

Recommended Posts

fred_beaucamp

Good afternoon


the purpose is the following :

I want to open a Word file, run a macro ans save the result as a .docx file.

I don't succeed in saving the document with a .docx extension :

$word = ObjCreate("Word.Application")
$word.visible = True
Local $sDocument = "C:\Bazar\isa2docx\AGCMFR.doc"
$word.Documents.open($sDocument)
$word.Run("PaysageUnix66bis")
$word.ActiveDocument.SaveAs("C:\Bazar\isa2docx\AGCMFR.docx")
$word.Application.Quit

the error is

$word.ActiveDocument^ERROR

Error the requested action with this object as failed

 

I'm on a win10 computer wth a x64 processor with Microsoft Office 2016

Please Help me.

thanks

 

Share this post


Link to post
Share on other sites
water

BTW: It is always a good idea to do some error checking after calling a function. So you always know where the error arises. If not AutoIt might crash a few statements later and you start to debug at the wrong place ;) 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
fred_beaucamp

Hi !

Thanks Subz and water for your answers!

The code who works is the following :

#include <Word.au3>

Local $sDocument = "C:\Bazar\isa2docx\AGCMFR.doc"
Local $oWord = _Word_Create()
Local $oDoc = _Word_DocOpen($oWord,$sDocument)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Erreur ouverture fichier")

    $oWord.Run("PaysageUnix66bis")
_Word_DocSaveAs($oDoc, "C:\Bazar\isa2docx\AGCMFR.docx", $WdFormatDocumentDefault)
_Word_DocClose($oDoc)
_Word_Quit($oWord)

We can close this topic !

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

×