Using VBA to pull text from a shape in a word document

  • by
using-vba-to-pull-text-from-a-shape-in-a-word-document

first time poster and quite new to VBA. I’m trying to basically just grab the text from inside a shape on a word document. I’m testing it by using super simple code:

Sub textgrab()
MsgBox ActiveDocument.Shapes("Rectangle 85").TextFrame.TextRange.Text
End Sub

Except I keep getting the error:

Run-time error '-2147024809 (80070057)':
The item with the specified name wasn't found.

I can’t figure out why I get this error, though, as when I go into the word document and go to the top menu, hit the shape format tab, and in the arrange section, i select ‘selection pane’, and get a full list of all the shapes, ‘Rectangle 85’ is there, and when i select it, it highlights the appropriate box i’m trying to grab the value from.

Any help on how to fix this would be greatly appreciated. I’m sure it’s a stupid mistake, i’ve just been spending an embarrassing amount of time trying to figure it out.

Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *