DOORS DXL vs. MS Word OLE commands

Dear Forum,

I've been trying out the OLE calls on Microsoft Word with some measure of success. I've also read some forum posts regarding this issue although I can't find a specific answer.

Task: Export DOORS data to Word. Hardly novel but the built-in exporter doesn't quite do the job. We have a company template and I can set the Word Heading Styles according to the if statement: if object.heading is not empty then set Word Heading according to level (o).

That's fine and it produces just what I need. The first problem I have is that of placement. I have created a bookmark and have tried the three OLE commands (put, get, & method) every which way round. The object browser in Word VBA talks about word.application.gotoBookmark Ref: "doors_bkmk" but i just can't build the syntax in DXL to call this method. It's also mildly frustrating that I can't work out how to test the code step by step so I don't even know if I'm close.

I've been trying:

objWord = oleCreateAutoObject("Word.Application")
olePut(objWord, "Visible", true)
oleGet(objWord, "Documents", objDocs)
clear oleAutoArgs
put(oleAutoArgs, "My Path To Template")
oleMethod(objDocs, "Open", oleAutoArgs, objDoc)
oleGet(objWord, "Selection", objSel)

This works and the Word template opens, cursor set to the front page.

Then there is some code to work out if it's a heading or requirement...and then the following code to actually paste (in this case a requirement):

setRichClip(richText o."Object Heading", word_heading_name)
oleMethod(objSel, "Paste")

So this is all fine. I've had to empty the template and once DOORS has exported, I need to copy paste the resulting output into the correct place in the final company template, which is a fairly unnecessary step as it shouldn't be too hard to get DXL to move the cursor to a bookmark.

I've recorded a macro and the output is something like:
Selection.GoTo What:=wdGoToBookmark, Name:="insert"
The VBA object browser talks about something different and I'm just not sure what to do next. I've tried various calls to Goto What, GotoItem, wdGoToBookmark, Bookmarks, etc., all in differing forms without success.

As an example, for the second problem this is what I've been doing to disable screenupdating. The macro code produces:
application.screenupdating = false

so from the example above, the variable objWord is word.application so I then try:
oleGet(objWord, "ScreenUpdating", objUpdate)
clear oleAutoArgs
put(oleAutoArgs, "False")
oleMethod(objUpdate, oleAutoArgs)

Which doesn't work, actually it doesn't compile. Then I tried:

put(oleAutoArgs, "False")
oleMethod(objWord, "ScreenUpdating", oleAutoArgs)

Where objWord is Word.Application as above...but no cigar...

I've also tried running a macro - again using word.application.run with oleMethod calling the macro name...

I'd really like to understand more as I can see much more use of this "remote control" functionality but I'm struggling...

Please can someone help...:)

Many thanks,

N


NigelRoberts - Mon Jul 18 08:00:03 EDT 2016

Re: DOORS DXL vs. MS Word OLE commands
Antonio__Norkus - Mon Jul 18 11:54:22 EDT 2016

From an in-house exporter I've maintained:

 

const int wdGoToBookmark = -1

bool gotobookmark (OleAutoObj &objDocument, OleAutoObj &objRange, string bookmark)
{     
        // Sets objRange to the specified bookmark.

        string s
        clear autoargs
        put(autoargs, "What", wdGoToBookmark)                         // Goto bookmark.
        put(autoargs, "Name", bookmark)                               // The bookmark name.
        s = oleMethod(objDocument, "GoTo", autoargs, objRange)        // Attempt to go.
        if (!null s) ack s                                            // Report any OLE error.
        return (s == null)                                            // Return true if successful.

} // gotobookmark

 

Re: DOORS DXL vs. MS Word OLE commands
NigelRoberts - Tue Jul 19 04:19:46 EDT 2016

Thank you Antonio,

 

I'm probably going to show myself up here but...:)

 

when I run this code, word does not go to my bookmark and the error message states: "Problem with OLE argument names".

 

To confirm: objDocument is my objDoc as defined above, and objRange is uninitialised at the time this code is executed.

 

Also, if I leave "Name" as it is in your code the error changes to "This bookmark does not exist". When I replace "Name" with "book_one" (my bookmark name) the error message states "Problem with OLE arguments".

 

N

Re: DOORS DXL vs. MS Word OLE commands
O.Wilkop - Tue Jul 19 05:43:52 EDT 2016

NigelRoberts - Tue Jul 19 04:19:46 EDT 2016

Thank you Antonio,

 

I'm probably going to show myself up here but...:)

 

when I run this code, word does not go to my bookmark and the error message states: "Problem with OLE argument names".

 

To confirm: objDocument is my objDoc as defined above, and objRange is uninitialised at the time this code is executed.

 

Also, if I leave "Name" as it is in your code the error changes to "This bookmark does not exist". When I replace "Name" with "book_one" (my bookmark name) the error message states "Problem with OLE arguments".

 

N

Hi,

 

try the following:

const int wdGoToBookmark = -1

OleAutoObj objWord = oleCreateAutoObject("Word.Application")

olePut(objWord, "ScreenUpdating", false);


olePut(objWord, "Visible", true)
OleAutoObj objDocs;
oleGet(objWord, "Documents", objDocs)
OleAutoArgs     oleAutoArgs     = create
clear oleAutoArgs
put(oleAutoArgs, "D:/WordTemplate.docx")
OleAutoObj objDoc;
oleMethod(objDocs, "Open", oleAutoArgs, objDoc)
OleAutoObj objSel;
oleGet(objWord, "Selection", objSel)

clear(oleAutoArgs)
put(oleAutoArgs, "What", wdGoToBookmark)
put(oleAutoArgs, "Name", "insert")
OleAutoObj objRange
oleMethod(objDoc, "GoTo", oleAutoArgs, objRange)


oleMethod(objRange, "Select")
oleMethod(objSel, "Paste")


olePut(objWord, "ScreenUpdating", true);

 

It will open the Word template at "D:/WordTemplate.docx" and insert whatever you currently have in your clipboard at the position of the "insert" bookmark.

Screen updating gets disabled in line 5, enabled in line 30

The actual moving to the bookmark is taken from Antonios post above.

To actually paste your clipboard you either have to call "Select" on the range object (line 26) and then "Paste" on the Selection object (line 27) or you can call "Paste" on the Range object directly.

 

Hope this works for you.

Re: DOORS DXL vs. MS Word OLE commands
NigelRoberts - Wed Jul 20 03:59:40 EDT 2016

O.Wilkop - Tue Jul 19 05:43:52 EDT 2016

Hi,

 

try the following:

const int wdGoToBookmark = -1

OleAutoObj objWord = oleCreateAutoObject("Word.Application")

olePut(objWord, "ScreenUpdating", false);


olePut(objWord, "Visible", true)
OleAutoObj objDocs;
oleGet(objWord, "Documents", objDocs)
OleAutoArgs     oleAutoArgs     = create
clear oleAutoArgs
put(oleAutoArgs, "D:/WordTemplate.docx")
OleAutoObj objDoc;
oleMethod(objDocs, "Open", oleAutoArgs, objDoc)
OleAutoObj objSel;
oleGet(objWord, "Selection", objSel)

clear(oleAutoArgs)
put(oleAutoArgs, "What", wdGoToBookmark)
put(oleAutoArgs, "Name", "insert")
OleAutoObj objRange
oleMethod(objDoc, "GoTo", oleAutoArgs, objRange)


oleMethod(objRange, "Select")
oleMethod(objSel, "Paste")


olePut(objWord, "ScreenUpdating", true);

 

It will open the Word template at "D:/WordTemplate.docx" and insert whatever you currently have in your clipboard at the position of the "insert" bookmark.

Screen updating gets disabled in line 5, enabled in line 30

The actual moving to the bookmark is taken from Antonios post above.

To actually paste your clipboard you either have to call "Select" on the range object (line 26) and then "Paste" on the Selection object (line 27) or you can call "Paste" on the Range object directly.

 

Hope this works for you.

Thank you Muchly...

 

Got the code working now, and I can turn off screenupdating which really speeds things up!

 

Many thanks...

 

N

Re: DOORS DXL vs. MS Word OLE commands
swain_sweta - Wed Oct 18 09:05:21 EDT 2017

is there any way or DXL code , which can automate ole insertion . as every time when i am trying to edit an OLE i have double click on it, edit it and  and save it. everyday i am dealing with 100 of OLE objects