Sign in to follow this  
Followers 0
Jury

Word UDF changes _Word_ functions

15 posts in this topic

Loving AutoIt v3.3.10.0 but I don't understand thinking as to why the old Word UDF functions such as _WordMacroRun and _WordDocPropertySet no longer exist.  Can't these things be done with new versions of Word or have these yet to be added or is there a better method of doing these functions (if so are there any examples somewhere?)

jury

Share this post


Link to post
Share on other sites



Oh! playing around with Waters example here:

'?do=embed' frameborder='0' data-embedContent>>

I've done below which changes the property Title to cat - now for figuring out how to do  _WordMacroRun

 

 

#include <Word.au3>
#include <MsgBoxConstants.au3>

$processing = @MyDocumentsDir & '\AutoIt_code\getter\processing\'
$out = @MyDocumentsDir & '\AutoIt_code\getter\processing\out\'


Global $oWord = _Word_Create()
$sDocument = $processing & "\test.doc"
$oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True)
$oDoc.BuiltInDocumentProperties('Title').value = 'cat'
_Word_DocSaveAs($oDoc, $processing & "\test_out.doc")

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

perhaps adding something like these below - Macro17 is the pre-recorded Word macro (thes don't work though) any ideas?

$oDoc.DoCmd.RunMacro("Macro17")

or

$oDoc.RunMacro ("Macro17")
Edited by Jury

Share this post


Link to post
Share on other sites

Loving AutoIt v3.3.10.0 but I don't understand thinking as to why the old Word UDF functions such as _WordMacroRun and _WordDocPropertySet no longer exist.  Can't these things be done with new versions of Word or have these yet to be added or is there a better method of doing these functions (if so are there any examples somewhere?)

jury

This functions have been removed because they were only wrappers for a one line function.

This things can still be done with new versions of Word.

Maybe I'm going to create a wiki section to answer this kind of questions and add some examples ...


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

#5 ·  Posted (edited)

Thanks Water I'm now trying to write a script to run this Word macro using the Excel With..EndWith example on help item 'COM Extensions to AutoIt' - I can't see any other way to do this using with  _Word_DocFindReplace.  Please tell me if I'm going in the correct direction.

Sub ex_header()
    WordBasic.RemoveHeader
End Sub
Edited by Jury

Share this post


Link to post
Share on other sites

$oAppl.Run("ex_header")

should do what you want. $oAppl is the Word application object as returned by _Word_Create.


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

So if I do this

Global $oWord = _Word_Create()
$sDocument = $processing & "\2331.rtf"
$oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, False)
$oAppl = ObjCreate("Word.Application")
$oDoc.$oAppl.Run("ex_header")

 

I get:

Microsoft Visual Basic

Run-time error 'S09':

The RemoveHeader command is not available because a document window is not active.



Share this post


Link to post
Share on other sites

Should be:

Global $oWord = _Word_Create()
$sDocument = $processing & "\2331.rtf"
$oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, False)
$oWord.Run("ex_header")

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

#9 ·  Posted (edited)

Oh! now I see I can't get it into my head that these object names are assigned rather than being pre-defined in the COM object (if that makes any sense) and of course you did tell me the " $oAppl is the Word application object as returned by _Word_Create".  This opens up all sorts of fun possibilities regarding macros - and I now see why you didn't include this  as a functions in the UDF - once again thanks ever so much.

jury

Edited by Jury

Share this post


Link to post
Share on other sites

So the Macro problem could be solved?

What's your problem with _Word_DocFindReplace?


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

Oh I see I've got two topics here - no problems now with _Word_DocFindReplace it works perfectly so everything is fine now but as for the Word Macro can't I just run that macro instruction (WordBasic.RemoveHeader) without having it in a macro I've created in Word?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Never used it myself before, but could you try:

$oWord.WordBasic.RemoveHeader
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

Great! works a treat - I should've given that a try.

Thanks (until next time I'm afraid)

jury

Share this post


Link to post
Share on other sites

Glad I could solve your problems :)

See you.


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

I have added a section to the AutoIt wiki about the Word UDF describing the script breaking changes and how to mimic old functionality.

Ii's still work in progress but if something is missing, please let me know.


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
Sign in to follow this  
Followers 0