Sign in to follow this  
Followers 0
saywell

Word UDF functionality

6 posts in this topic

#1 ·  Posted (edited)

Tucked away in the examples of the word udf are some interesting feature like:

$sText = $oWordApp.Activedocument.Range.Text for getting text

and

$oDoc.Range.insertAfter for entering text

However, I can't find anything in the help files to explain their syntax.

For example, the first example seems only to get the first line of text - how do I get ALL the text? Presumably something to do with 'range'?

I'd be grateful if anyone could point me towards a source of info on what similar functionality might be tucked away with these examples, and some details on how to use them. Do they, perhaps, use syntax from another language?

Thanks,

William

Edited by saywell

Share this post


Link to post
Share on other sites



They are using COM objects which are documented by Microsoft. AutoIt has no control over them.

You need to figure out which COM object is being used and look up the documentation for it.

Share this post


Link to post
Share on other sites

Thanks.

W.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

OK so this is Visual Basic for Applications - VBA - as used in Word etc macros, I think.

Lots of documentation on the web.

BUT I need help with the syntax for calling these from Autoit

For example, I can use $oDoc.Range.insertAfter to insert at end of text or

$0Doc.Selection.EndKey to put cursor at end of line.

However, if I try $oDoc.Selection.EndKey Unit:=wdStory to put cursor at the end of the document [as per <ctrl>-End] I get an error due to the space.

So my question is, how do I get Autoit to implement commands with an argument separated by the space?

Regards,

William

Edited by saywell

Share this post


Link to post
Share on other sites

However, if I try $oDoc.Selection.EndKey Unit:=wdStory to put cursor at the end of the document [as per <ctrl>-End] I get an error due to the space.

Everything after the space are parameters to the method. So the above statement should read in AutoIt:

$wdStory = 6
$oDoc.Selection.EndKey($wdStory)

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

#6 ·  Posted (edited)

Everything after the space are parameters to the method. So the above statement should read in AutoIt:

$wdStory = 6
$oDoc.Selection.EndKey($wdStory)

Many thanks. That's the syntax sorted, but where did the $wdStory = 6 come from? Specifically, the value 6?

Found it - 6 is the value for end of text!

William

Edited by saywell

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