How to change text within Text Box in Word using VBA

Asked

Viewed 466 times

1

I am trying to change the text within the Word Text Box. I am not using any Activex for this, it is the normal Word text box same. How do I do this by programming by VBA?

I can make changes to the normal texts I write by Word, but when the text is inside a Text Box, I cannot change it by this method. I did so to change the normal texts:

    With ActiveDocument.Content.Find
     .Text = "Estado Civil"
     .Forward = True
     .Execute
     .Replacement.Text = "###"
     .Execute Replace:=wdReplaceAll, Forward:=True
    End With

I searched through various documentations and tutorials and found nothing. Thank you in advance!

1 answer

0


Hello. One way to do this is by accessing the collection of "shapes" objects that exist in the document, but note that there are some "shapes" that do not support this property, so you have to test the object type. For that you can use the property HasText.

ActiveDocument.Shapes(1).TextFrame.TextRange.Text = "Novo Texto"
  • Thank you very much!!!!!!

  • Hello the best way to thank is to validate the answer. I’m glad it helped

  • I think I got it validated, I don’t know how to use Stackoverflow yet

Browser other questions tagged

You are not signed in. Login or sign up in order to post.