Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

TextBox and Tables - a couple of questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Cronin - 13 Mar 2006 07:39 GMT
Folks;

What I want to do is essentially 'mail-merge' but the user is not going
to be placing merge tags.
They will simply put placeholders that I will substitute with data in
my script.
They will be placing the text in normal layout, inside of textboxes,
and inside of tables.
Could be some or all of the above.

How do I determine if there are any TEXT BOXES and then iterate over
them changing .Text any 'abc' to 'xyz'? (TextBoxes just puzzle me...)

For Tables I've figured out that I can do:
With ActiveDocument.Tables(1)
    For i = 2 To .Rows.Count
        For j = 1 To .Columns.Count
            [do something with .Cell(i,j).Range.Text]
        Next j
    Next i
End With

But:
1) How do I determine how many tables there are and then iterate over
them successively?
2) Is there a smarter way than walking every thru cell and checking for
.Range.Text?

In the general layout (not in a TextBox or a Table) is this the
preferred solution:
With Selection.Find.Text ="abc"
.Replacement.Text = "xyz""
.Forward = True
.Wrap = 1
.Format = False
End With
ReplaceAll()

Thanks for any insight!!
Steve
Jezebel - 13 Mar 2006 08:28 GMT
Unless you are concerned that the placemarker text may occur outside your
tables and textboxes and should *not* be substituted in that context, you
can just use Find and Replace: if the Search domain is set to ALL, that will
catch the textboxes also. There's no need to deal with tables and textboxes
individually.

If you really want to do it the hard way, you can iterate tables using code
like

Dim pTable as Word.Table
For each pTable in ActiveDocument.Tables
   ...
Next

There's no need to deal with each cell separately, either. You can just use
pTable.Range to refer to the whole thing, eg

With pTable.Range.Find
   .Text = "..."
   .Replace.Text = "..."
   .Execute Replace:=wdReplaceAll
End with

To iterate textboxes, use something like

Dim pTextBox as Word.Range

on error resume next        'Ignore error if there are NO textboxes
Set pTextBox  = ActiveDocument.StoryRanges(wdTextFrameStory)
on error goto 0

Do until pTextBox is nothing
   .... do whatever
   set pTextBox = pTextBox.NextStoryRange
Loop

> Folks;
>
[quoted text clipped - 36 lines]
> Thanks for any insight!!
> Steve
Steve Cronin - 13 Mar 2006 08:38 GMT
How do I set the Search domain to ALL?
Jezebel - 13 Mar 2006 09:06 GMT
On the Find and Replace dialog, click more, and select All. From VBA use
wdFindContinue.

> How do I set the Search domain to ALL?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.