Sign in to follow this  
Followers 0
mark2004

Syntax issue with Microsoft COM Method

3 posts in this topic

I would like to have my script perform a COM Method in Word2003. The problem is that

the PrintOut Method has multiple arguments, not all of which are needed. The description of

the Printout method is given below from the Visual Basic Help within Word.

oEnvelope.PrintOut(ExtractAddress, Address, AutoText, OmitReturnAddress, ReturnAddress, ReturnAutoText, PrintBarCode, PrintFIMA, Size, Height, Width, FeedSource, AddressFromLeft, AddressFromTop, ReturnAddressFromLeft, ReturnAddressFromTop, DefaultFaceUp, DefaultOrientation, PrintEPostage, Vertical, RecipientNamefromLeft, RecipientNamefromTop, RecipientPostalfromLeft, RecipientPostalfromTop, SenderNamefromLeft, SenderNamefromTop, SenderPostalfromLeft, SenderPostalfromTop)

An example of the method is given below for Visual Basic within Word.

Activedocument.Envelope.PrintOut Address:="John Smith", ReturnAddress:=Application.UserAddress, Size:="Size 10", PrintBarCode:=True

I have no problems in Autoit creating the Word Object and the Envelope object but I cannot get it to successfully

print out the envelope. I have tried so many syntax permutations it would be impossible to list them all.

If one of you could just try to get this simple method to work in Autoit I would really appreciate it. It is driving me

freakin crazy. I know there are other ways to accomplish this such as _WordMacroRun etc but this is more about

understanding why I cannot get a method with multiple named arguments to work. I know that I will eventually

need this type of thing in the future.

Thanks

Share this post


Link to post
Share on other sites



Well, I think I have figured it out.

The key is to keep the parameters in the proper order and use the following syntax:

$odoc.envelope.Printout(var1, var2, var3.....etc)

This seems obvious now but the misleading part comes from using the Visual Basic Editor in Word

to examine a macro for the purpose of discovering how the COM object works. In Visual basic you

don't need to keep track of parameter order. You can simply do the following:

doc.envelope.printout var4:="John Smith", var1:=True, var5:=False

The order is not important since you can identify each parameter explicitly in the function statement.

Just pay attention to the original documentation for the full list of parameters and be sure to include all parameters

that come before the ones that you need for your statement.

I hope this helps someone else who may go down the same road. Lesson learned. :)

Share this post


Link to post
Share on other sites

Well, I think I have figured it out.

The key is to keep the parameters in the proper order and use the following syntax:

$odoc.envelope.Printout(var1, var2, var3.....etc)

This seems obvious now but the misleading part comes from using the Visual Basic Editor in Word

to examine a macro for the purpose of discovering how the COM object works. In Visual basic you

don't need to keep track of parameter order. You can simply do the following:

doc.envelope.printout var4:="John Smith", var1:=True, var5:=False

The order is not important since you can identify each parameter explicitly in the function statement.

Just pay attention to the original documentation for the full list of parameters and be sure to include all parameters

that come before the ones that you need for your statement.

I hope this helps someone else who may go down the same road. Lesson learned. :)

Yes, this piece of information is very important when porting COM methods into Autoit.

I would have never figured out that I have to come to this long lines of code finally:

With $StatusTabla.Activesheet

;~  1 <OptionalAttribute> Password As Object, _
;~  2 <OptionalAttribute> DrawingObjects As Object, _
;~  3 <OptionalAttribute> Contents As Object, _
;~  4 <OptionalAttribute> Scenarios As Object, _
;~  5 <OptionalAttribute> UserInterfaceOnly As Object, _
;~  6 <OptionalAttribute> AllowFormattingCells As Object, _
;~  7 <OptionalAttribute> AllowFormattingColumns As Object, _
;~  8 <OptionalAttribute> AllowFormattingRows As Object, _
;~  9 <OptionalAttribute> AllowInsertingColumns As Object, _
;~  10 <OptionalAttribute> AllowInsertingRows As Object, _
;~  11 <OptionalAttribute> AllowInsertingHyperlinks As Object, _
;~  12 <OptionalAttribute> AllowDeletingColumns As Object, _
;~  13 <OptionalAttribute> AllowDeletingRows As Object, _
;~  14 <OptionalAttribute> AllowSorting As Object, _
;~  15 <OptionalAttribute> AllowFiltering As Object, _
;~  16 <OptionalAttribute> AllowUsingPivotTables As Object _

;~ .Protect(  1,        2,  3,  4,   5,  6,   7,     8, 9,   10,   11,  12, 13, 14,   15,   16)
    .Protect("secret", True, True, True, True, False, True, True, False, False, False, False, False, True, True, False)
    EndWith

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