Link to home
Start Free TrialLog in
Avatar of geo90
geo90

asked on

Microsoft Word Object Library

I am issuing a find/replace command and it is only replacing certain instances that are plain text in the document, but not instances of the word that are contained inside of a text box.

When using the fing/replace within word it works fine.

Dim wordApp As Word.Application
Dim wordDoc As Word.Document

Set wordApp = New Word.Application

Set wordDoc = wordApp.Documents.Open("Test.doc", ReadOnly:=False)

wordApp.Selection.Find.Execute "this", False, False, False, False, False, True, wdFindContinue, False, "that", wdReplaceAll

what is the scope of the wordApp.Selection without specifying it like i'm not?

Is there something i can do to make sure it looks everywhere in the document?

Thanks,
geo90
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Please maintain your open questions.  For the record:

Questions Asked 12
Last 10 Grades Given B B B A A B A B  
Question Grading Record 8 Answers Graded / 8 Answers Received

Anthony
Let me rewrite your statement with named parameters for clarity.

wordApp.Selection.Find.Execute _
FindText:="this", MatchCase:=False, _
MatchWholeWord:=False, MatchWildcards:=False, _
MatchSoundsLike:=False, MatchAllWordForms:=False, _
Forward:=True, Wrap:=wdFindContinue, _
Format:=False, ReplaceWith:="that", Replace:=wdReplaceAll

===========================================

I would recommend the following:
1. moving the selection to the start of the document before this command
2. exploring other parts of the document, such as another story, headings, footings, and forms.  You will have to select or move the selection to these other parts of the document.

===========================================
If this text is inside a Userform, you might have to instantiate some VBE objects to get to them.  You won't be able use Find/replace commands to change it. :-(
Avatar of geo90
geo90

ASKER

1. How do you move the selection to the start of the doc?
2. The text that isn't being replaced is just a simple text box.
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for maintaining your open questions, but I believe you may have overlooked the following question:
Desktop Icon placement Date: 12/26/2001 08:05PM PST
https://www.experts-exchange.com/questions/20306682/Microsoft-Word-Object-Library.html

Anthony
Anthony,

Your question link referenced this (current) question.
aikimark,

You absolutely right, the link should be:
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20249221

Anthony
Avatar of geo90

ASKER

How are you naming your text boxes?
When I'm in word I do insert > text box and it just puts a text box on the doc and i don't see anywhere where i can set a name property.
open the properties dialog window (right mouse click) and you can name the textbox controls.

You might be better off adding text frames instead of a textbox.  These are accessable through the Shapes collection.
Avatar of geo90

ASKER

I found that i can loop through the shapes and then test to see if it is a text box (through the type property)
and if it is a text box i issue a select command and then i repeat my find/replace command for each one.

Thanks for your help.