473,608 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.Charac ters.Count;
Object forward = true ;
Object wrap = Microsoft.Offic e.Interop.Word. WdFindWrap.wdFi ndStop;
Object oCollapse = WdCollapseDirec tion.wdCollapse End;

bool bFound = false;

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

oFnd.ClearForma tting();
oFnd.Forward = true;
oFnd.Wrap = WdFindWrap.wdFi ndStop;
oFnd.Text = "Hello";

ExecuteFind(oFn d);

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

oRng.Collapse(r ef oCollapse);

ExecuteFind(oFn d);
}

private Boolean ExecuteFind(Wor d.Find find)
{
return ExecuteFind(fin d, 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 matchAllWordFor ms = 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(re f findText, ref matchCase,
ref matchWholeWord, ref matchWildcards, ref matchSoundsLike ,
ref matchAllWordFor ms, ref forward, ref wrap, ref format,
ref replaceWith, ref replace, ref matchKashida,
ref matchDiacritics , ref matchAlefHamza, ref matchControl);
}

Feb 13 '07 #1
1 8762
You could try posting this to an Office Programming group. If nobody here
has an answer, maybe somebody there would.

Robin S.
----------------------------------
<wi**********@g mail.comwrote in message
news:11******** *************@a 75g2000cwd.goog legroups.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.Charac ters.Count;
Object forward = true ;
Object wrap = Microsoft.Offic e.Interop.Word. WdFindWrap.wdFi ndStop;
Object oCollapse = WdCollapseDirec tion.wdCollapse End;

bool bFound = false;

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

oFnd.ClearForma tting();
oFnd.Forward = true;
oFnd.Wrap = WdFindWrap.wdFi ndStop;
oFnd.Text = "Hello";

ExecuteFind(oFn d);

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

oRng.Collapse(r ef oCollapse);

ExecuteFind(oFn d);
}

private Boolean ExecuteFind(Wor d.Find find)
{
return ExecuteFind(fin d, 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 matchAllWordFor ms = 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(re f findText, ref matchCase,
ref matchWholeWord, ref matchWildcards, ref matchSoundsLike ,
ref matchAllWordFor ms, ref forward, ref wrap, ref format,
ref replaceWith, ref replace, ref matchKashida,
ref matchDiacritics , ref matchAlefHamza, ref matchControl);
}

Feb 13 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5152
by: Darryl Kerkeslager | last post by:
I hope that although this is 25% Access and 75% Word, that someone will know ... The whole problem here arises because 1) Microsoft acknowledges an 'issue' wherein TextInput type FormFields are lost when doing a MailMerge and 2) the fix that they have proposed is both inadequate and won't work from Access. http://support.microsoft.com/?kbid=286841 The part of the code below that actually performs the merge is great; the core of it is...
4
3393
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property 'Value2'). So I suppose I'm using a incompatible type lib. I'm using Excel 2002 : Excel 10.0 Object Library
2
13500
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to execute a MailMerge to create mailing labels or customized letters. A label name known to MS Word MailMerge mailing label wizard may be used or a template file containing the field names Line1 thru Line5 for each record to be printed. If a...
2
2176
by: Al_P via DotNetMonster.com | last post by:
I have: Win2K Office2000 Working in VB.Net (2003) My .Net project has a reference to Word 9.0 Instantiating things in a simple and straightforward manner: Dim word as Word.Application Dim doc As Word.Document Dim range As Word.Range
1
3702
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
8
4206
by: John Salerno | last post by:
I figured my first step is to install the win32 extension, which I did, but I can't seem to find any documentation for it. A couple of the links on Mark Hammond's site don't seem to work. Anyway, all I need to do is search in the Word document for certain strings and either delete them or replace them. Easy enough, if only I knew which function, etc. to use. Hope someone can push me in the right direction.
0
5556
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
4
12427
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
1
4944
by: mr k | last post by:
Hi, I wanted to use mail merge with forms but Text form fields are not retained during mail merge in Word, I got the code from Microsoft but it doesn't remember the text form field options such as the maximum length of the text (which I need) and the text format (would be ideal but can do without if need be) I have posted the code below, so please can you help!?? Thanks in advance... Sub PreserveMailMergeFormFieldsNewDoc() Dim...
0
8063
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8003
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6817
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.