Word table and VBA

E

Euclid

So far I've been able to create a table in Access, output it to .rtf, attach
it to an existing Word document and set the column widths all from within
Access. Now I need to further format the table by using the Find method. I
need to go through the table, find any row that has the word "SUBTOTAL" in it
and make the font bold for that row. I've been able to get it to find the
first instance of the row with "SUBTOTAL" in it but then it doesn't continue
through the rest of the document. I'm sure the code is easy but it eludes
me. Thanks.
 
D

Doug Robbins - Word MVP

Use the following code:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="SUBTOTAL", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=True) = True
Selection.Rows(1).Range.Font.Bold = True
Selection.Collapse wdCollapseEnd
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
E

Euclid

I works perfectly, though I can't say I understand it completely. Here's
what I have:

wdApp.ActiveDocument.Tables(2).Select
Set MySelection = wdApp.Selection
MySelection.HomeKey wdStory
MySelection.Find.ClearFormatting
With MySelection.Find
Do While .Execute(Findtext:="TOTAL", Forward:=True,
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=True) = True
MySelection.Rows(1).Range.Font.Bold = True
MySelection.Collapse wdCollapseEnd
Loop
End With


I have no idea what the lines for HomeKey and ClearFormatting mean or why
you need the Collapse line either. (By the way, I changed the text to
"TOTAL" from "SUBTOTAL" because I have a last line with the Grand Total in it
that needs to be bold also.)

The point is that it works and I'm grateful for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top