speed up replacement loop

W

woody

i have a prototype document, it has placeholders in teh
format of <<DATANAME>>. what i currently doing is i set
teh current page as teh range and then do multiple search
and replaces against the range until i have exhausted all
placeholder names.

what i woudl like to do is
set the current page as range,
do a wildcard search for "(<<)[A-Z](>>)",
do a case statement against the found text
do a replace statement replaceing the found text with a
program supplied value
and loop back until i hit the bottom of the page.

i figure that has to be faster than multiple crawls thru
teh same page and i have no idea how to do this.

any help woudl be greatly appreciated.

thanx Woody
 
W

woody

that shows me how to find the keywords but not how to tell
what i have found.

for instance:

Dear <<NAME>>, per your request we are inclduing details
about our new <<PRODUCT>>. we thank that you will find it
exteremly interesting.

Sincerely

<<MARKETINGREP>>
<<COMPANY>>

the wildcard search will find the keywords but how do i
tell what has been found so i can plug in the appropriate
data?

sorry. Programming isnt new to me but but this aspect is
very new to me.

thanks for your help.

Woody
-----Original Message-----
Hi woody

You can make a wildcard search in a VBA macro by setting the MatchWildcards
property to True when you have your Find object. The following article will
be helpful in working out how to build your wildcard string

Finding and replacing characters using wildcards
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

If text is found, the Text property of the Selection or range will return
the found string.

Hopefully, this should be anough to help you modify your macro.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com


woody said:
i have a prototype document, it has placeholders in teh
format of <<DATANAME>>. what i currently doing is i set
teh current page as teh range and then do multiple search
and replaces against the range until i have exhausted all
placeholder names.

what i woudl like to do is
set the current page as range,
do a wildcard search for "(<<)[A-Z](>>)",
do a case statement against the found text
do a replace statement replaceing the found text with a
program supplied value
and loop back until i hit the bottom of the page.

i figure that has to be faster than multiple crawls thru
teh same page and i have no idea how to do this.

any help woudl be greatly appreciated.

thanx Woody


.
 
J

Jonathan West

Hi Woody.

This bit of code will demonstrate the concept

Sub WildCardsearch()
Dim strFoundText as String
With Selection.Find
.MatchWildcards = True
.Text = "\<\<*\>\>"
.Wrap = wdFindStop
Do While .Execute
strFoundText = Selection.Text
MsgBox strFoundText
Loop
End With
End Sub

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com


woody said:
that shows me how to find the keywords but not how to tell
what i have found.

for instance:

Dear <<NAME>>, per your request we are inclduing details
about our new <<PRODUCT>>. we thank that you will find it
exteremly interesting.

Sincerely

<<MARKETINGREP>>
<<COMPANY>>

the wildcard search will find the keywords but how do i
tell what has been found so i can plug in the appropriate
data?

sorry. Programming isnt new to me but but this aspect is
very new to me.

thanks for your help.

Woody
-----Original Message-----
Hi woody

You can make a wildcard search in a VBA macro by setting the MatchWildcards
property to True when you have your Find object. The following article will
be helpful in working out how to build your wildcard string

Finding and replacing characters using wildcards
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

If text is found, the Text property of the Selection or range will return
the found string.

Hopefully, this should be anough to help you modify your macro.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com


woody said:
i have a prototype document, it has placeholders in teh
format of <<DATANAME>>. what i currently doing is i set
teh current page as teh range and then do multiple search
and replaces against the range until i have exhausted all
placeholder names.

what i woudl like to do is
set the current page as range,
do a wildcard search for "(<<)[A-Z](>>)",
do a case statement against the found text
do a replace statement replaceing the found text with a
program supplied value
and loop back until i hit the bottom of the page.

i figure that has to be faster than multiple crawls thru
teh same page and i have no idea how to do this.

any help woudl be greatly appreciated.

thanx Woody


.
 
D

Doug Robbins - Word MVP

Hi Woody,

To start with, why aren't you using mailmerge?

Another way you could do it would be to replace each of your dataitems with
a { DOCVARIABLE "dataname" } field and then use

ActiveDocument.Variables("dataname").Value = program supplied value

and finally an

ActiveDocument.Fields.Update

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
woody said:
that shows me how to find the keywords but not how to tell
what i have found.

for instance:

Dear <<NAME>>, per your request we are inclduing details
about our new <<PRODUCT>>. we thank that you will find it
exteremly interesting.

Sincerely

<<MARKETINGREP>>
<<COMPANY>>

the wildcard search will find the keywords but how do i
tell what has been found so i can plug in the appropriate
data?

sorry. Programming isnt new to me but but this aspect is
very new to me.

thanks for your help.

Woody
-----Original Message-----
Hi woody

You can make a wildcard search in a VBA macro by setting the MatchWildcards
property to True when you have your Find object. The following article will
be helpful in working out how to build your wildcard string

Finding and replacing characters using wildcards
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

If text is found, the Text property of the Selection or range will return
the found string.

Hopefully, this should be anough to help you modify your macro.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com


woody said:
i have a prototype document, it has placeholders in teh
format of <<DATANAME>>. what i currently doing is i set
teh current page as teh range and then do multiple search
and replaces against the range until i have exhausted all
placeholder names.

what i woudl like to do is
set the current page as range,
do a wildcard search for "(<<)[A-Z](>>)",
do a case statement against the found text
do a replace statement replaceing the found text with a
program supplied value
and loop back until i hit the bottom of the page.

i figure that has to be faster than multiple crawls thru
teh same page and i have no idea how to do this.

any help woudl be greatly appreciated.

thanx Woody


.
 
W

woody

i'm not using mail merge since i generate values from code
as well as pull in from a database, plus as it runs it
flags teh records on the database so the selected records
wont be selected in teh next run, pulls and builds
condensed histories from the database and also generates
an excel spreadsheet from the data and several emails
simultaneously.

i have the code below working with 1 problem. after i get
done with a page. i insert a new page, grab the next
record from the database, build a serial number and all
teh other fun stuff and then go into the loop again.

teh problem is that the find automatically returns a not
found condition. how do i get the vb to reset the range
to the current page, and refresh the find?

i sincerely appreciate all help i can get on this.

thanks
Woody
_________________________________________________________
Dim fndRange As Range

Dim strWord As String
Dim intMove As Integer

Dim bolEnd As Boolean

Set fndRange = ActiveDocument.Content

fndRange.SetRange 0, (ActiveDocument.Characters.Count)

Do Until bolEnd = True

With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = False
.MatchCase = False
.MatchWildcards = True
.Wrap = wdFindStop
.Execute FindText:="\[([A-Z]*)\]"

If .Found = False Then
fndRange.Collapse direction:=wdCollapseStart
bolEnd = True
MsgBox "no more"
Else
strWord = Selection
MsgBox strWord
Select Case strWord
Case Is = "
Code:
"
With Selection
.Text = "12345-AA-2003"
intMove = Selection.Move
(Unit:=wdCharacter, Count:=1)
If intMove < 1 Then
bolEnd = True
End If
End With
Case Is = "[TODAY]"
With Selection
.Text = "7/1/2003"
intMove = Selection.Move
(Unit:=wdCharacter, Count:=1)
If intMove < 1 Then
bolEnd = True
End If
End With
Case Is = "[VISA]"
With Selection
.Text = "H2b"
intMove = Selection.Move
(Unit:=wdCharacter, Count:=1)
If intMove < 1 Then
bolEnd = True
End If
End With
End Select
End If
End With
Loop

Set fndRange = Nothing

End Sub
[QUOTE]
-----Original Message-----
Hi Woody,

To start with, why aren't you using mailmerge?

Another way you could do it would be to replace each of your dataitems with
a { DOCVARIABLE "dataname" } field and then use

ActiveDocument.Variables("dataname").Value = program supplied value

and finally an

ActiveDocument.Fields.Update

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
[QUOTE="woody"]
that shows me how to find the keywords but not how to tell
what i have found.

for instance:

Dear <<NAME>>, per your request we are inclduing details
about our new <<PRODUCT>>.  we thank that you will find it
exteremly interesting.

Sincerely

<<MARKETINGREP>>
<<COMPANY>>

the wildcard search will find the keywords but how do i
tell what has been found so i can plug in the appropriate
data?

sorry.  Programming isnt new to me but but this aspect is
very new to me.

thanks for your help.

Woody[QUOTE]
-----Original Message-----
Hi woody

You can make a wildcard search in a VBA macro by[/QUOTE] setting
the MatchWildcards[QUOTE]
property to True when you have your Find object. The following article will
be helpful in working out how to build your wildcard string

Finding and replacing characters using wildcards [/QUOTE]
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm[QUOTE]
If text is found, the Text property of the Selection or range will return
the found string.

Hopefully, this should be anough to help you modify[/QUOTE] your
macro.[QUOTE]
--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com


i have a prototype document, it has placeholders in teh
format of <<DATANAME>>.  what i currently doing is i set
teh current page as teh range and then do multiple search
and replaces against the range until i have exhausted all
placeholder names.

what i woudl like to do is
set the current page as range,
do a wildcard search for "(<<)[A-Z](>>)",
do a case statement against the found text
do a replace statement replaceing the found text with a
program supplied value
and loop back until i hit the bottom of the page.

i figure that has to be faster than multiple crawls thru
teh same page and i have no idea how to do this.

any help woudl be greatly appreciated.

thanx Woody


.
[/QUOTE][/QUOTE]


.
[/QUOTE]
 
D

Doug Robbins - Word MVP

Hi Woody,

If I understand what you are doing, the following will take care of it:

Dim foundrange As Range
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\[([A-Z]*)\]", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set foundrange = Selection.Range
Select Case foundrange.Text
Case Is = "
Code:
"
With Selection
.Text = "12345-AA-2003"
End With
Case Is = "[TODAY]"
With Selection
.Text = "7/1/2003"
End With
Case Is = "[VISA]"
With Selection
.Text = "H2b"
End With
End Select
Loop
End With


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
[QUOTE="woody"]
i'm not using mail merge since i generate values from code
as well as pull in from a database, plus as it runs it
flags teh records on the database so the selected records
wont be selected in teh next run, pulls and builds
condensed histories from the database and also generates
an excel spreadsheet from the data and several emails
simultaneously.

i have the code below working with 1 problem.  after i get
done with a page.  i insert a new page, grab the next
record from the database, build a serial number and all
teh other fun stuff and then go into the loop again.

teh problem is that the find automatically returns a not
found condition.  how do i get the vb to reset the range
to the current page, and refresh the find?

i sincerely appreciate all help i can get on this.

thanks
Woody
_________________________________________________________
Dim fndRange As Range

Dim strWord  As String
Dim intMove  As Integer

Dim bolEnd   As Boolean

Set fndRange = ActiveDocument.Content

fndRange.SetRange 0, (ActiveDocument.Characters.Count)

Do Until bolEnd = True

With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = False
.MatchCase = False
.MatchWildcards = True
.Wrap = wdFindStop
.Execute FindText:="\[([A-Z]*)\]"

If .Found = False Then
fndRange.Collapse direction:=wdCollapseStart
bolEnd = True
MsgBox "no more"
Else
strWord = Selection
MsgBox strWord
Select Case strWord
Case Is = "[CODE]"
With Selection
.Text = "12345-AA-2003"
intMove = Selection.Move
(Unit:=wdCharacter, Count:=1)
If intMove < 1 Then
bolEnd = True
End If
End With
Case Is = "[TODAY]"
With Selection
.Text = "7/1/2003"
intMove = Selection.Move
(Unit:=wdCharacter, Count:=1)
If intMove < 1 Then
bolEnd = True
End If
End With
Case Is = "[VISA]"
With Selection
.Text = "H2b"
intMove = Selection.Move
(Unit:=wdCharacter, Count:=1)
If intMove < 1 Then
bolEnd = True
End If
End With
End Select
End If
End With
Loop

Set fndRange = Nothing

End Sub
[QUOTE]
-----Original Message-----
Hi Woody,

To start with, why aren't you using mailmerge?

Another way you could do it would be to replace each of your dataitems with
a { DOCVARIABLE "dataname" } field and then use

ActiveDocument.Variables("dataname").Value = program supplied value

and finally an

ActiveDocument.Fields.Update

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
[QUOTE="woody"]
that shows me how to find the keywords but not how to tell
what i have found.

for instance:

Dear <<NAME>>, per your request we are inclduing details
about our new <<PRODUCT>>.  we thank that you will find it
exteremly interesting.

Sincerely

<<MARKETINGREP>>
<<COMPANY>>

the wildcard search will find the keywords but how do i
tell what has been found so i can plug in the appropriate
data?

sorry.  Programming isnt new to me but but this aspect is
very new to me.

thanks for your help.

Woody
-----Original Message-----
Hi woody

You can make a wildcard search in a VBA macro by setting
the MatchWildcards
property to True when you have your Find object. The
following article will
be helpful in working out how to build your wildcard
string

Finding and replacing characters using wildcards
 http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

If text is found, the Text property of the Selection or
range will return
the found string.

Hopefully, this should be anough to help you modify your
macro.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com


i have a prototype document, it has placeholders in teh
format of <<DATANAME>>.  what i currently doing is i set
teh current page as teh range and then do multiple
search
and replaces against the range until i have exhausted
all
placeholder names.

what i woudl like to do is
set the current page as range,
do a wildcard search for "(<<)[A-Z](>>)",
do a case statement against the found text
do a replace statement replaceing the found text with a
program supplied value
and loop back until i hit the bottom of the page.

i figure that has to be faster than multiple crawls thru
teh same page and i have no idea how to do this.

any help woudl be greatly appreciated.

thanx Woody


.
[/QUOTE]


.
[/QUOTE][/QUOTE]
 
W

woody

the prototype document is 1 page in this project but in
similar projects it can be any length. I need 1 set of
the prototype per selected record from the database, I
also generate serial numbers programmatically and past
history which can range from none to a lot, also as teh
letters are generated the selected records have to be
flagged so they will not be processed again, emails are
sent to 3 different addresses, and i generate a
spreadsheet as a document checklist.

since the generated output gets shipped to one email
address easiest to just process teh data, paste copy of
prototype to end of document, process variables and repeat
as often as needed.

its a bizarre project but interesting. Im glad its done, i
applied what i learned from you and john into some
completed projects and they work better now also.

Thank you.

sincerely

Woody

PS

how does that document variable collection work? can you
have more than 1 occurence of a particular variable? can
you dynamically add occurrences?

sounds interesting but never used it. i will try to learn
what i can about it.

-----Original Message-----
Hi Woody,

To start with, why aren't you using mailmerge?

Another way you could do it would be to replace each of your dataitems with
a { DOCVARIABLE "dataname" } field and then use

ActiveDocument.Variables("dataname").Value = program supplied value

and finally an

ActiveDocument.Fields.Update

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
woody said:
that shows me how to find the keywords but not how to tell
what i have found.

for instance:

Dear <<NAME>>, per your request we are inclduing details
about our new <<PRODUCT>>. we thank that you will find it
exteremly interesting.

Sincerely

<<MARKETINGREP>>
<<COMPANY>>

the wildcard search will find the keywords but how do i
tell what has been found so i can plug in the appropriate
data?

sorry. Programming isnt new to me but but this aspect is
very new to me.

thanks for your help.

Woody
-----Original Message-----
Hi woody

You can make a wildcard search in a VBA macro by
setting
the MatchWildcards
property to True when you have your Find object. The following article will
be helpful in working out how to build your wildcard string

Finding and replacing characters using wildcards
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm
If text is found, the Text property of the Selection or range will return
the found string.

Hopefully, this should be anough to help you modify
your
macro.
--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com


i have a prototype document, it has placeholders in teh
format of <<DATANAME>>. what i currently doing is i set
teh current page as teh range and then do multiple search
and replaces against the range until i have exhausted all
placeholder names.

what i woudl like to do is
set the current page as range,
do a wildcard search for "(<<)[A-Z](>>)",
do a case statement against the found text
do a replace statement replaceing the found text with a
program supplied value
and loop back until i hit the bottom of the page.

i figure that has to be faster than multiple crawls thru
teh same page and i have no idea how to do this.

any help woudl be greatly appreciated.

thanx Woody


.


.
 

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

Similar Threads


Top