Results 1 to 2 of 2
2003-09-18, 14:14 #1
- Join Date
- Apr 2002
- Sydney, Australia
- Thanked 0 Times in 0 Posts
Search using Range fails (Word 2002, VBA)
I use the following code to check if the word 'enclosure' appears in the current section:
If modSharedCode.Encl = True Then
Function Encl() As Boolean
Dim intSection As Integer
Dim rngDoc As Range
intSection = Selection.Information(wdActiveEndSectionNumber)
Set rngDoc = ActiveDocument.Sections(intSection).Range
.Text = "enclos"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
If rngDoc.Find.Execute = True Then
Encl = True
Encl = False
The next time my code performs a search using the standard Selection object, Word 2002 hangs and causes problems until I reboot the PC. I have experienced similar problems using the range object in other code. Does anyone know why? Is this a bug?
2003-10-04, 20:24 #2
- Join Date
- Mar 2002
- Thanked 29 Times in 29 Posts
Re: Search using Range fails (Word 2002, VBA)
I copied the Encl function into a module, and performed some tests. Running Encl didn't cause problems with subsequent searches with the Selection object. It didn't matter whether either of the searches found something or not. So I suspect there must be something else the matter with your code.
I don't know if this is still relevant, but if so, you might post a demo document with the code (replace sensitive information by dummy text).
For the record, I am using Word 2002 SP-2 on Windows XP Home SP-1.