?
Solved

Microsoft Word Object Library

Posted on 2002-05-31
10
Medium Priority
?
215 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:geo90
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7047484
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
0
 
LVL 46

Expert Comment

by:aikimark
ID: 7049121
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. :-(
0
 

Author Comment

by:geo90
ID: 7049180
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Accepted Solution

by:
aikimark earned 800 total points
ID: 7049542
Selection.StartOf wdStory

I thought you'd be able to iterate through the shapes collection, just like you do with PowerPoint, but the shape isn't exposing its text to my sample code.

If you know the names of the textbox controls ahead of time, you can directly access them and their text with:

ActiveDocument.Textbox1.Text
ActiveDocument.Textbox2.Text
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7049603
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
http://www.experts-exchange.com/visualbasic/Q_20306682.html

Anthony
0
 
LVL 46

Expert Comment

by:aikimark
ID: 7049629
Anthony,

Your question link referenced this (current) question.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7049684
aikimark,

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

Anthony
0
 

Author Comment

by:geo90
ID: 7051997
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.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 7052790
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.
0
 

Author Comment

by:geo90
ID: 7055102
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question