Help on .NET Word Object Library Range Find.Execute infinite Loop

W

winston.heng

Hi,

Thanks for reading this posting. I have been cracking my head on
solving the infinite loop
when i call the following section code. Any help or advise is greatly
appreciated =D

Thanks in advance.

Cheers!
Winston

//i follow the sample provided by microsoft
http://msdn2.microsoft.com/en-us/library/aa192495(office.11).aspx#wordobject_link7

Object start = 0;
Object end = oWordDoc.Characters.Count;
Object forward = true ;
Object wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindStop;
Object oCollapse = WdCollapseDirection.wdCollapseEnd;

bool bFound = false;

Microsoft.Office.Interop.Word.Range oRng = oWordDoc.Range(ref start,
ref end);
Microsoft.Office.Interop.Word.Find oFnd = oRng.Find;

oFnd.ClearFormatting();
oFnd.Forward = true;
oFnd.Wrap = WdFindWrap.wdFindStop;
oFnd.Text = "Hello";

ExecuteFind(oFnd);

while (oFnd.Found)
{
oRng.Hyperlinks.Add(oRng, ref oURL, ref oMissing, ref oMissing,
ref oMissing,
ref oTargetFrame);

oRng.Collapse(ref oCollapse);

ExecuteFind(oFnd);
}

private Boolean ExecuteFind(Word.Find find)
{
return ExecuteFind(find, Type.Missing, Type.Missing);
}

private Boolean ExecuteFind(
Word.Find find, Object wrapFind, Object forwardFind)
{
// Simple wrapper around Find.Execute:
Object findText = Type.Missing;
Object matchCase = Type.Missing;
Object matchWholeWord = Type.Missing;
Object matchWildcards = Type.Missing;
Object matchSoundsLike = Type.Missing;
Object matchAllWordForms = Type.Missing;
Object forward = forwardFind;
Object wrap = wrapFind;
Object format = Type.Missing;
Object replaceWith = Type.Missing;
Object replace = Type.Missing;
Object matchKashida = Type.Missing;
Object matchDiacritics = Type.Missing;
Object matchAlefHamza = Type.Missing;
Object matchControl = Type.Missing;

return find.Execute(ref findText, ref matchCase,
ref matchWholeWord, ref matchWildcards, ref matchSoundsLike,
ref matchAllWordForms, ref forward, ref wrap, ref format,
ref replaceWith, ref replace, ref matchKashida,
ref matchDiacritics, ref matchAlefHamza, ref matchControl);
}
 
R

RobinS

You could try posting this to an Office Programming group. If nobody here
has an answer, maybe somebody there would.

Robin S.
 

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