Using find object

F

Felipe Garcia

i have few templates that have a few variables in the
format [variable] and *variable*.
when i use the word component to find the [variable] it
works fine. but when i use the component to find the
*variable* i enter in an infinite loop.

what's wrong ?
thanks.
-- Felipe Garcia
private void ExtractManualVars(ref string
ManualVars)
{
StringBuilder sbVars;
string pattern = "*";
object objtext;
object Missing =
System.Reflection.Missing.Value;
Word.Find fnd =
_wordapp.Selection.Find;

object Format =
Word.WdFindWrap.wdFindContinue;
int docsize = 0;
int start = 0;
int end = 0;
bool ret;

sbVars = new StringBuilder();
docsize =
_worddoc.Characters.Count;

fnd.ClearFormatting();
while(end < docsize)
{
objtext = pattern;

ret = fnd.Execute(ref
objtext, ref Missing, ref Missing, ref Missing,
ref Missing, ref
Missing, ref Missing, ref Format, ref Missing,
ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref
Missing);

if (!ret)
return;

start =
_wordapp.Selection.Range.End;

if (start < end)
return;

objtext = pattern;
fnd.Execute(ref objtext,
ref Missing, ref Missing, ref Missing,
ref Missing, ref
Missing, ref Missing, ref Format, ref Missing,
ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref
Missing);

end =
_wordapp.Selection.Range.Start;

_wordapp.Selection.SetRange
(start, end);

sbVars.AppendFormat("*{0}
*,", _wordapp.Selection.Range.Text);

object objunit =
Word.WdUnits.wdWord;
object objtwo = 2;
_wordapp.Selection.Move
(ref objunit, ref objtwo);
}
}
 
C

Cindy M -WordMVP-

Hi Felipe,
object Format =
Word.WdFindWrap.wdFindContinue;
I'm having some problems converting your .NET code into the
VBA I'm more familiar with, (especially since you don't
comment what's supposed to be happening) but the above is
definitely dangerous when automating Word's Find
functionality. wdFindContinue will keep on looping through
the document, even if the thing you're trying to find
doesn't exist. Use wdFindStop, instead and see if that
helps.
i have few templates that have a few variables in the
format [variable] and *variable*.
when i use the word component to find the [variable] it
works fine. but when i use the component to find the
*variable* i enter in an infinite loop.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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