How would I search for a string inside of an OLE table? I've been looking for examples but have not been able to find anything close to what I want to do. Is the same thing possible for OLE figures? |
Re: search for string inside of OLE table |
Re: search for string inside of OLE table doors36677 - Thu Sep 16 14:28:08 EDT 2010 |
Re: search for string inside of OLE table lsand - Thu Sep 16 14:48:23 EDT 2010 The moral of the story is although you can't directly access OLE text to search it, you can still do it if you have the appropriate interface to the external program which opens the OLE object. |
Re: search for string inside of OLE table Zetareticuli - Mon Dec 27 10:07:43 EST 2010 I am facing the same issue like you. Zetareticuli, did you manage to automatize your procedure ? It would be really hepfull for us. Best regards |
Re: search for string inside of OLE table jbjacques - Tue Jun 12 08:53:30 EDT 2012 Here is an example I created for searching for "TBD" within OLEs in a module. It may serve as a starting point for you. // Process Ole /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a sample program that checks for TBDs in an OLE in the Object Text. This program ignores objects with multiple OLEs. It assumes that the OLE is first order (i.e., does not itself contain an embedded OLE). Excel does not provide a method for searching a chart, so such OLEs are added to an error string in this example Static and unregistered OLEs cannot be activated and searched, so they are added to an error string in this example This example only searches in OLEs from Word or Excel. It is possible to expand its capabilities to other applications. It is written for Office 2003, but should still work for Office 2007. It may be modified to search for other words than "TBD" ------------------------------------------------------------------------------*/ const int xlWorksheet = -4167 const int xlFormulas = -4123 Module m Object o string sName string sErr bool bIsActivated bool bFoundTBD bool bIsStatic bool bIsUnregistered int iObjMax, iCount, iType OleAutoObj objDoc OleAutoObj objApp OleAutoObj objSelection OleAutoObj objFind OleAutoObj objCells OleAutoObj objCell OleAutoObj objSheet OleAutoArgs objArgs = create string sError = "" string sTBDObjects = "The following objects have OLEs with TBDs: " string sNoTBDObjects = "The following objects have OLEs that do not have TBDs: " int iNumberOfOles string sObjId m = current if (null m) { errorBox "This function must be run from within a module" halt } iObjMax = 0 iCount = 0 for o in m do iObjMax++ progressStart(dbExplorer, "Find TDBs in OLEs", "Something", iObjMax) for o in m do { iCount++ progressStep iCount sObjId = identifier o "" progressMessage "Processing " iCount " of " iObjMax " (" sObjId ")" iNumberOfOles = oleCount(o."Object Text") if (iNumberOfOles > 1) { sError = sError "Object " sObjId " has more than one OLE\n" continue } if (iNumberOfOles == 0) continue // only one OLE, so let's process it. bIsStatic = containsStaticOle(o."Object Text") bIsUnregistered = containsUnregisteredOle(o."Object Text") if (bIsStatic) { bIsActivated = false } else if (bIsUnregistered) { bIsActivated = false } else bIsActivated = oleActivate(o) if (!bIsActivated) { sError = sError "Unable to activate OLE for object " sObjId ": " if (bIsStatic) sError = sError "It is Static\n" else if (bIsUnregistered) sError = sError "It is Unregistered\n" else sError = sError "Reason unknown\n" continue } objDoc = oleGetAutoObject(o) if (null objDoc) { sError = sError "Unable to get document handle for OLE object in " sObjId "\n" if bIsActivated then oleDeactivate(o) oleCloseAutoObject objDoc continue } sErr = oleGet(objDoc, "Application", objApp) if (!null sErr) { sError = sError "Cannot get application object for OLE in " sObjId "\n" oleDeactivate(o) continue } if (null objApp) { sError = sError "Unable to get application for activated document in " sObjId "\n" if bIsActivated then oleDeactivate(o) continue } oleGet(objApp, "Name", sName) if (matches("Word", sName)) { oleGet(objApp, "Selection", objSelection) oleGet(objSelection, "Find", objFind) oleMethod(objFind, "ClearFormatting") olePut(objFind, "Text", "TBD") olePut(objFind, "MatchWholeWord", true) olePut(objFind, "Format", false) oleMethod(objFind, "Execute") oleGet(objFind, "Found", bFoundTBD) if (bFoundTBD) sTBDObjects = sTBDObjects sObjId "\n" else sNoTBDObjects = sNoTBDObjects sObjId "\n" } else if (matches("Excel", sName)) { // get the cells on the active sheet oleGet(objApp, "ActiveSheet", objSheet) sErr = oleGet(objSheet, "Type", iType) if (!null sErr) sError = sError "Unable to get Excel type: " sErr "\n" else if (iType == xlWorksheet) { oleGet(objApp, "Cells", objCells) clear objArgs put(objArgs, "What", "TBD") put(objArgs, "LookIn", xlFormulas) put(objArgs, "MatchCase", true) put(objArgs, "SearchFormat", false) oleMethod(objCells, "Find", objArgs, objCell) if (!null objCell) sTBDObjects = sTBDObjects sObjId "\n" else sNoTBDObjects = sNoTBDObjects sObjId "\n" } else sError = sError "Cannot search Excel Chart in " sObjId "\n" } else { sError = sError "Application " sName " not currently supported\n" } if bIsActivated then oleDeactivate(o) } progressStop if (sError != "") warningBox sError infoBox sTBDObjects infoBox sNoTBDObjects
|
Re: search for string inside of OLE table David_G_Bond - Tue Jun 12 10:48:17 EDT 2012 Here is an example I created for searching for "TBD" within OLEs in a module. It may serve as a starting point for you. // Process Ole /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a sample program that checks for TBDs in an OLE in the Object Text. This program ignores objects with multiple OLEs. It assumes that the OLE is first order (i.e., does not itself contain an embedded OLE). Excel does not provide a method for searching a chart, so such OLEs are added to an error string in this example Static and unregistered OLEs cannot be activated and searched, so they are added to an error string in this example This example only searches in OLEs from Word or Excel. It is possible to expand its capabilities to other applications. It is written for Office 2003, but should still work for Office 2007. It may be modified to search for other words than "TBD" ------------------------------------------------------------------------------*/ const int xlWorksheet = -4167 const int xlFormulas = -4123 Module m Object o string sName string sErr bool bIsActivated bool bFoundTBD bool bIsStatic bool bIsUnregistered int iObjMax, iCount, iType OleAutoObj objDoc OleAutoObj objApp OleAutoObj objSelection OleAutoObj objFind OleAutoObj objCells OleAutoObj objCell OleAutoObj objSheet OleAutoArgs objArgs = create string sError = "" string sTBDObjects = "The following objects have OLEs with TBDs: " string sNoTBDObjects = "The following objects have OLEs that do not have TBDs: " int iNumberOfOles string sObjId m = current if (null m) { errorBox "This function must be run from within a module" halt } iObjMax = 0 iCount = 0 for o in m do iObjMax++ progressStart(dbExplorer, "Find TDBs in OLEs", "Something", iObjMax) for o in m do { iCount++ progressStep iCount sObjId = identifier o "" progressMessage "Processing " iCount " of " iObjMax " (" sObjId ")" iNumberOfOles = oleCount(o."Object Text") if (iNumberOfOles > 1) { sError = sError "Object " sObjId " has more than one OLE\n" continue } if (iNumberOfOles == 0) continue // only one OLE, so let's process it. bIsStatic = containsStaticOle(o."Object Text") bIsUnregistered = containsUnregisteredOle(o."Object Text") if (bIsStatic) { bIsActivated = false } else if (bIsUnregistered) { bIsActivated = false } else bIsActivated = oleActivate(o) if (!bIsActivated) { sError = sError "Unable to activate OLE for object " sObjId ": " if (bIsStatic) sError = sError "It is Static\n" else if (bIsUnregistered) sError = sError "It is Unregistered\n" else sError = sError "Reason unknown\n" continue } objDoc = oleGetAutoObject(o) if (null objDoc) { sError = sError "Unable to get document handle for OLE object in " sObjId "\n" if bIsActivated then oleDeactivate(o) oleCloseAutoObject objDoc continue } sErr = oleGet(objDoc, "Application", objApp) if (!null sErr) { sError = sError "Cannot get application object for OLE in " sObjId "\n" oleDeactivate(o) continue } if (null objApp) { sError = sError "Unable to get application for activated document in " sObjId "\n" if bIsActivated then oleDeactivate(o) continue } oleGet(objApp, "Name", sName) if (matches("Word", sName)) { oleGet(objApp, "Selection", objSelection) oleGet(objSelection, "Find", objFind) oleMethod(objFind, "ClearFormatting") olePut(objFind, "Text", "TBD") olePut(objFind, "MatchWholeWord", true) olePut(objFind, "Format", false) oleMethod(objFind, "Execute") oleGet(objFind, "Found", bFoundTBD) if (bFoundTBD) sTBDObjects = sTBDObjects sObjId "\n" else sNoTBDObjects = sNoTBDObjects sObjId "\n" } else if (matches("Excel", sName)) { // get the cells on the active sheet oleGet(objApp, "ActiveSheet", objSheet) sErr = oleGet(objSheet, "Type", iType) if (!null sErr) sError = sError "Unable to get Excel type: " sErr "\n" else if (iType == xlWorksheet) { oleGet(objApp, "Cells", objCells) clear objArgs put(objArgs, "What", "TBD") put(objArgs, "LookIn", xlFormulas) put(objArgs, "MatchCase", true) put(objArgs, "SearchFormat", false) oleMethod(objCells, "Find", objArgs, objCell) if (!null objCell) sTBDObjects = sTBDObjects sObjId "\n" else sNoTBDObjects = sNoTBDObjects sObjId "\n" } else sError = sError "Cannot search Excel Chart in " sObjId "\n" } else { sError = sError "Application " sName " not currently supported\n" } if bIsActivated then oleDeactivate(o) } progressStop if (sError != "") warningBox sError infoBox sTBDObjects infoBox sNoTBDObjects
I have another question : how could I get one specific cell from a OLE object ? For the moment I do not see how to do that. Thanks in advance Best regards |
Re: search for string inside of OLE table David_G_Bond - Tue Jun 12 10:48:17 EDT 2012 Here is an example I created for searching for "TBD" within OLEs in a module. It may serve as a starting point for you. // Process Ole /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a sample program that checks for TBDs in an OLE in the Object Text. This program ignores objects with multiple OLEs. It assumes that the OLE is first order (i.e., does not itself contain an embedded OLE). Excel does not provide a method for searching a chart, so such OLEs are added to an error string in this example Static and unregistered OLEs cannot be activated and searched, so they are added to an error string in this example This example only searches in OLEs from Word or Excel. It is possible to expand its capabilities to other applications. It is written for Office 2003, but should still work for Office 2007. It may be modified to search for other words than "TBD" ------------------------------------------------------------------------------*/ const int xlWorksheet = -4167 const int xlFormulas = -4123 Module m Object o string sName string sErr bool bIsActivated bool bFoundTBD bool bIsStatic bool bIsUnregistered int iObjMax, iCount, iType OleAutoObj objDoc OleAutoObj objApp OleAutoObj objSelection OleAutoObj objFind OleAutoObj objCells OleAutoObj objCell OleAutoObj objSheet OleAutoArgs objArgs = create string sError = "" string sTBDObjects = "The following objects have OLEs with TBDs: " string sNoTBDObjects = "The following objects have OLEs that do not have TBDs: " int iNumberOfOles string sObjId m = current if (null m) { errorBox "This function must be run from within a module" halt } iObjMax = 0 iCount = 0 for o in m do iObjMax++ progressStart(dbExplorer, "Find TDBs in OLEs", "Something", iObjMax) for o in m do { iCount++ progressStep iCount sObjId = identifier o "" progressMessage "Processing " iCount " of " iObjMax " (" sObjId ")" iNumberOfOles = oleCount(o."Object Text") if (iNumberOfOles > 1) { sError = sError "Object " sObjId " has more than one OLE\n" continue } if (iNumberOfOles == 0) continue // only one OLE, so let's process it. bIsStatic = containsStaticOle(o."Object Text") bIsUnregistered = containsUnregisteredOle(o."Object Text") if (bIsStatic) { bIsActivated = false } else if (bIsUnregistered) { bIsActivated = false } else bIsActivated = oleActivate(o) if (!bIsActivated) { sError = sError "Unable to activate OLE for object " sObjId ": " if (bIsStatic) sError = sError "It is Static\n" else if (bIsUnregistered) sError = sError "It is Unregistered\n" else sError = sError "Reason unknown\n" continue } objDoc = oleGetAutoObject(o) if (null objDoc) { sError = sError "Unable to get document handle for OLE object in " sObjId "\n" if bIsActivated then oleDeactivate(o) oleCloseAutoObject objDoc continue } sErr = oleGet(objDoc, "Application", objApp) if (!null sErr) { sError = sError "Cannot get application object for OLE in " sObjId "\n" oleDeactivate(o) continue } if (null objApp) { sError = sError "Unable to get application for activated document in " sObjId "\n" if bIsActivated then oleDeactivate(o) continue } oleGet(objApp, "Name", sName) if (matches("Word", sName)) { oleGet(objApp, "Selection", objSelection) oleGet(objSelection, "Find", objFind) oleMethod(objFind, "ClearFormatting") olePut(objFind, "Text", "TBD") olePut(objFind, "MatchWholeWord", true) olePut(objFind, "Format", false) oleMethod(objFind, "Execute") oleGet(objFind, "Found", bFoundTBD) if (bFoundTBD) sTBDObjects = sTBDObjects sObjId "\n" else sNoTBDObjects = sNoTBDObjects sObjId "\n" } else if (matches("Excel", sName)) { // get the cells on the active sheet oleGet(objApp, "ActiveSheet", objSheet) sErr = oleGet(objSheet, "Type", iType) if (!null sErr) sError = sError "Unable to get Excel type: " sErr "\n" else if (iType == xlWorksheet) { oleGet(objApp, "Cells", objCells) clear objArgs put(objArgs, "What", "TBD") put(objArgs, "LookIn", xlFormulas) put(objArgs, "MatchCase", true) put(objArgs, "SearchFormat", false) oleMethod(objCells, "Find", objArgs, objCell) if (!null objCell) sTBDObjects = sTBDObjects sObjId "\n" else sNoTBDObjects = sNoTBDObjects sObjId "\n" } else sError = sError "Cannot search Excel Chart in " sObjId "\n" } else { sError = sError "Application " sName " not currently supported\n" } if bIsActivated then oleDeactivate(o) } progressStop if (sError != "") warningBox sError infoBox sTBDObjects infoBox sNoTBDObjects
progressStart(dbExplorer, "Find TDBs in OLEs", "Something", iObjMax) for o in m do { Any ideas? Thanks, Ken. |
Re: search for string inside of OLE table mcnairk - Tue Jun 12 12:20:16 EDT 2012 The command "progressStart" with its parameters should stand alone, it is line 58 in my environment. line 59 contains the command "for o in m do {" |
Re: search for string inside of OLE table SystemAdmin - Tue Jun 12 13:06:08 EDT 2012 Thanks Mike. Thanks also to David for providing the code; I've been looking for something like this for years! Ken. |
Re: search for string inside of OLE table mcnairk - Wed Jun 13 08:47:09 EDT 2012 THX Ken. |
Re: search for string inside of OLE table mcnairk - Wed Jun 13 09:29:50 EDT 2012
|
Re: search for string inside of OLE table David_G_Bond - Wed Jun 13 14:24:30 EDT 2012
Also, should I close MSWord after each object (allowing the user to see the progress bar, but might slow down execution since it has to keep re-opening Word) or wait till all objects in the module have been processed, before moving onto the next module. My intended use is to create a simple interface for users so they can enter the search string and a list of modules to search (typically 50 active modules that currently takes about 12 minutes to trawl...) I found the following paper a useful primer on this subject: http://download-na.telelogic.com/download/ugcagenda/W_DennisLockshine-Final-IntegratingDOORSintoWindows-VisualBasicandCOMprogrammingusingDOORSDXL.pdf Many thanks, Ken. |
Re: search for string inside of OLE table mcnairk - Fri Jun 15 08:14:28 EDT 2012
|