I am using the following VBA script to parse through a word document and open every OLE table object, copy the table, and paste back into word so that the data in the tables can be searchable. However, after the script runs for a while, Word gives me an error message stating "Word has encountered a problem. You will not be able to undo this action once it is completed. Do you want to continue?" Clicking yes leads the document to stop responding and crash with no changes been made. Choosing No just keeps repopping up the same message and I'm assuming this leads to the changes not being saved. Is something wrong with the script ? I thought it was somehow filling up the memory by opening all those OLE objects, but I think activating the word document shifts focus from the OLE object and hence closes the embedded table to continue parsing through the original document. I think it's probably related to each iteration of the loop although the message doesn't show up for every OLE table. I am stuck as to how to investigate further into what is causing this issue.
For idx = 1 to 10 On Error Resume Next Set wrdActDoc = ActiveDocument cnt = wrdActDoc.InlineShapes.Count For lShapeCnt = 1 To cnt If wrdActDoc.InlineShapes(lShapeCnt).Type = wdInlineShapeEmbeddedOLEObject Then If wrdActDoc.InlineShapes(lShapeCnt).OLEFormat.ProgID = "Word.Document.12" Then wrdActDoc.InlineShapes(lShapeCnt).OLEFormat.Activate Selection.Document.Select Selection.WholeStory Selection.Cut wrdActDoc.Activate Selection.PasteAndFormat (wdPasteDefault) End If End If Next lShapeCnt Next idx