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
Jezebel - 13 Jan 2005 00:07 GMT
If your document is strictly formatted -- which your description implies --
a much simpler approach is to use document properties and DocProperty
fields. Set up the document/template in advance with DocProperty fields for
the pieces of information you need to insert. The in your VBA code, all you
need do is redefine the property and update fields.
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
NWx - 13 Jan 2005 12:34 GMT
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
> If your document is strictly formatted -- which your description
> implies --
[quoted text clipped - 64 lines]
> Regards,
> Tomas
Jean-Guy Marcil - 13 Jan 2005 14:55 GMT
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

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
NWx - 13 Jan 2005 20:30 GMT
Hi,
Thank you for your reply.
I'll test this and hope it will work.
Best regards
> NWx was telling us:
> NWx nous racontait que :
[quoted text clipped - 15 lines]
> and
> Set Line4Range = MyRange.Paragraphs(4).Range