Hello,
First of all, let me thank you all for the invaluable help these forums have provided, as I'm new to DXL. I am trying to figure out a way to pass arguments to Word that will be used on a macro, but the documentation seems to be somewhat scarce or assumes a more proficient understanding of DXL. In any case, I am able to get the macro to run as part of the export, but I need certain arguments available for the macro and I haven't been able to figure out how to pass them using OleAutoArgs. Here's an example of part of the code (Argument1, Argument2, and Argument3 have a corresponding string variable with the same name in the Word macro):
const string cPropertyCustomDocumentProperties = "CustomDocumentProperties"
string Argument1
string Argument2
string Argument3
OleAutoObj objCustomProperties = null
OleAutoObj objProperty = null
OleAutoObj objDoc = null
objWord = oleGetAutoObject("Word.Application")
OleAutoArgs args = create ()
clear args
checkRes(oleGet (objWord, cPropertyActiveDocument, objDoc))
put(args, "Argument1", Argument1)
put(args, "Argument2", Argument1)
put(args, "Argument3", Argument1)
oleMethod(objDoc,cMethodAdd,args)
clear args
string macroName = "PostProcessing"
put(args, macroName)
oleMethod(objWord, "Run", args)
The above code runs the macro, but the variables remain empty, so I have been researching for an alternative approach and the closest I found was exporting the arguments as document properties using the function in the following Wiki:
https://www.ibm.com/developerworks/wikis/display/dxl/Add+'Document+Properties'+to+a+Word+doc
However, that function does not seem to work for me (I'm using DOORS 9.1 and Word 2010) since it returns a "null OleAutoObj parameter was passed into argument position 1" with respect to the following line: "checkRes(oleMethod(objCustomProperties,cMethodAdd,objArgBlock,objProperty))".
Any suggestions as to what might be the problem? Or any suggestions on how to get the code example above to pass the arguments?
Thank you in advance for your help!
Snowman07 - Mon Jul 23 19:10:54 EDT 2012 |
Re: Passing Arguments to Word to be used on Macro MichaelGeorg - Tue Jul 31 09:31:45 EDT 2012
Hi Snowman07,
handing Attributes to a Word Macro via Word Properties is the only way I know about. If you still want to do it that way, please try:
OleAutoObj objDocumentProperties = null
OleAutoObj objDocumentProperty = null
OleAutoArgs objArgBlockProp = null
//load document properties
oleGet( objDoc, "CustomDocumentProperties", objDocumentProperties )
//load property "Property x"
objArgBlockProp = create
put(objArgBlockProp, "Property x")
oleGet(objDocumentProperties, "Item", objArgBlockProp, objDocumentProperty)
//set value for "Property x" to "Value of Property x"
if ( !null objDocumentProperty )
{
olePut( objDocumentProperty, "Value", "Value of Property x")
}
Hope this will be of some help for you.
- Michael
|
Re: Passing Arguments to Word to be used on Macro Mathias Mamsch - Wed Aug 01 12:33:33 EDT 2012 MichaelGeorg - Tue Jul 31 09:31:45 EDT 2012
Hi Snowman07,
handing Attributes to a Word Macro via Word Properties is the only way I know about. If you still want to do it that way, please try:
OleAutoObj objDocumentProperties = null
OleAutoObj objDocumentProperty = null
OleAutoArgs objArgBlockProp = null
//load document properties
oleGet( objDoc, "CustomDocumentProperties", objDocumentProperties )
//load property "Property x"
objArgBlockProp = create
put(objArgBlockProp, "Property x")
oleGet(objDocumentProperties, "Item", objArgBlockProp, objDocumentProperty)
//set value for "Property x" to "Value of Property x"
if ( !null objDocumentProperty )
{
olePut( objDocumentProperty, "Value", "Value of Property x")
}
Hope this will be of some help for you.
- Michael
Hmm ... MSDN states that the run Method of Word.Application takes up to 30 parameters:
See here: http://msdn.microsoft.com/en-us/library/office/bb209121%28v=office.12%29.aspx
Trying this quickly with the following macro in my normal.dot
Function PostProcessing(x As Integer)
MsgBox "Hello " + Str(x)
End Function
with the following DXL script:
OleAutoObj objWord = oleGetAutoObject("Word.Application")
olePut(objWord, "Visible", true)
OleAutoArgs args = create ()
clear args
string macroName = "PostProcessing"
put(args, macroName)
put(args, 10) // here comes our argument
print oleMethod(objWord, "Run", args)
worked for me. If it does not work for you, it would be nice to find out why not? Regards, Mathias
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|