Jump to content

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


Recommended Posts

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

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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 !

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...