I have the following code which is able to open an embedded Excel table in Word, change the A1 cell to the string "Testing", and close the embedded Excel.
So far this only runs for the first object in the document. I'd like it to run through the entire count of objects that it finds, as seen below. See 'ActiveDocument.InlineShapes.Count'. I realize right now it only finds 1 to 1 in the first For loop. I've experimented with some different things but can't get it right. I'm guessing that I need a Do while loop in there... Any help figuring this out?
Sub TestOpenEditandSave()
Dim oOleFormat As OLEFormat
Dim lNumShapes As Long
Dim lShapeCnt As Long
Dim xlApp As Object
'ActiveDocument.InlineShapes.Count
For lShapeCnt = 1 To 1 'ActiveDocument.InlineShapes.Count
If ActiveDocument.InlineShapes(lShapeCnt).Type = wdInlineShapeEmbeddedOLEObject Then
If ActiveDocument.InlineShapes(lShapeCnt).OLEFormat.ProgID = "Excel.Sheet.8" Then
ActiveDocument.InlineShapes(lShapeCnt).OLEFormat.Edit
Set xlApp = GetObject(, "Excel.Application")
xlApp.Workbooks(1).Worksheets(1).Range("A1") = "Testing"
With Selection.Find
.ClearFormatting
.Text = "nothingMatch"
.Execute Forward:=True
End With
End If
End If
Next lShapeCnt
End Sub