By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,657 Members | 862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,657 IT Pros & Developers. It's quick & easy.

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

P: n/a
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/lib...rdobject_link7

Object start = 0;
Object end = oWordDoc.Characters.Count;
Object forward = true ;
Object wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindSto p;
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);
}

Feb 13 '07 #1
Share this Question
Share on Google+
1 Reply


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

Robin S.
----------------------------------
<wi**********@gmail.comwrote in message
news:11*********************@a75g2000cwd.googlegro ups.com...
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/lib...rdobject_link7

Object start = 0;
Object end = oWordDoc.Characters.Count;
Object forward = true ;
Object wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindSto p;
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);
}

Feb 13 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.