Overwriting text into a Word DOC with VBA

N

NWx

Hi,

I have a word DOC and I have to automatically replace some text in it with other.
The code uses Automation from an Access application to handle the Word DOC

Somewhere on a page of the Doc I have a text like this


Categorie A1



Dinsdag 25-01-2005 aanvang 19.00 De Boeg 2

&

Woensdag 26-01-2005 aanvang 19.00 De Welvaart 1























































I have the following VBA code to find that part of the doc and populate the table

.....

cSearchName = "Categorie[ ]@" & rsCat!CatNaam & rsCat!PouleNaam
Set myfind = oWrdDoc.Content.Find
myfind.MatchWildcards = True
myfind.Execute FindText:=cSearchName, Forward:=True
If myfind.Found Then
Set myrange = oWrdDoc.Range(myfind.Parent.Start, End:=oWrdDoc.Range.End)
Set tbl = myrange.Tables(1)

......

And now I know how to populate the table using

.....
Set rng = tbl.Cell(i, j).Range
rng.Text = MyValue

However, I don't know how to change the

Dinsdag 25-01-2005 aanvang 19.00 De Boeg 2

and

Woensdag 26-01-2005 aanvang 19.00 De Welvaart 1

The idea is I don't know what text I have to look for, but instead I have to replace the text on second and 4'th rows AFTER Categorie A1 (title). And on any of those rows, there are two variables who hold the value to replace with, one for normal text and one for bold.

As you see, I have to format also the values, to use Times Roman 14 normal for the beginning and bold for De Boeg 2

Can anyone give me a clue on how to do it?

Thank you

Regards,
Tomas
 
N

NWx

Thanks for reply

But I'd like to know, how can I select a certain text line in a range object
(line 2 and 4 in my case). Then know how to replace all text in the range
with other text

Regards
 
J

Jean-Guy Marcil

NWx was telling us:
NWx nous racontait que :
Thanks for reply

But I'd like to know, how can I select a certain text line in a range
object (line 2 and 4 in my case). Then know how to replace all text
in the range with other text

If your "lines" are in fact paragraphs (delimited by ¶) then all you need
is:
(Let's say the range object name is MyRange)

Dim Line2Range as Range
Dim Line4Range as Range

Set Line2Range = MyRange.Paragraphs(2).Range
and
Set Line4Range = MyRange.Paragraphs(4).Range

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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