PDA

View Full Version : Converting OLE image of a table into a 'searchable' table in Word



debkev1010
12-10-2014, 10:41 AM
I have a script that inserts OLEs into a Word document. The OLEs are in separate files (one OLE per file). The comment I most often get during the peer review process is "can you make your tables searchable?". The tables they're referring to are the objects that have been inserted by the script.

Here's the line that inserts the objects:
doc.ActiveWindow.Selection.InsertFile Filename:=path, Range:= "", ConfirmConversions:=False, Link:=False, Attachment:=False

What I end up doing to fix this is all manual. Say the OLE is an image of a Word table. After I run the script, I'll double click on the image/OLE object in the document 1. This opens document 2 with the image converted to its original table. I select all of the table and copy-n-paste it back into the document (replacing the OLE object). I tried to record a macro to see how my keystrokes/mouse clicks would be coded, but you can't open an object when you're in 'Record Macro' mode. Here are the steps I'm trying to write:

Existing code
1. after the script inserts the OLE into document 1, it selects the object using the Selection method

Missing code
2. perform the equivalent of double-clicking the object (this opens a new word document with the image converted to a table)
3. replacing the OLE object in document 1 with the converted table in document 2

Thanks,
Kevin

macropod
12-10-2014, 06:01 PM
There is nothing about the code line you posted that inherently creates an OLE object in the destination file - that would only occur if the inserted object was already an OLE object (e.g. an Excel sheet); it will not turn a Word table into an OLE object.

debkev1010
12-11-2014, 09:31 AM
Correct...the script doesn't create an OLE object; the files that it inserts into the destination file contain an OLE object...these files are created by a COTS software program (RPE for DOORS) when we export requirements out of DOORS and into a Word document (destination file). Each file contains one OLE. The RPE software includes a script called "insertOLEObjects" in which it loops through the destination file looking for references to these individual files with the OLEs. When it finds a reference, it inserts the appropriate file with the OLE into the destination file. However, when a peer reviewer performs a keyword search on the destination file, the contents of the OLE are ignored since it's an object. If I double click on the inserted OLE object in the destination file, another Word document opens with a 'searchable' table/figure. I then replace the OLE object with the 'searchable' table/figure manually. There's gotta be some way to automate this. I've started researching the SendKeys capability to see if I can accomplish this task.

Thanks,

macropod
12-11-2014, 12:30 PM
Without knowing what kind of OLE object you're working with, it's impossible to write code to convert it... The code to convert a Powerpoint Table, for example, would be entirely different from the code to convert an Excel table.