VBA WORD selection.find BUG??

D

Devacann

I'm from Brasil... my english is poor, then...
In a document, i set the selection.find to search the fallowing text with
wildcards ON = [a-z0-9]@[:;, ]@[A-Z a-z.]@[,^13-]@[ ^13R.Gg.]@[0-9
..X-]@[,^13]; some times it works, but sometimes they disappears with the
cursor and move to the first page of document.....

whatahell is this???
 
T

Tony Jollans

Selection.Find remembers settings within a Word session.

If, perhaps, someone has done a Find looking for formatted text in the UI,
and then you look for your text without resetting all the options, your text
may not be found.

Much better to use your own Range - its Find object will be initialised to
all default options when you create the Range.
 
D

Devacann

Tony Jollans said:
Selection.Find remembers settings within a Word session.

If, perhaps, someone has done a Find looking for formatted text in the UI,
and then you look for your text without resetting all the options, your text
may not be found.

Much better to use your own Range - its Find object will be initialised to
all default options when you create the Range.

--
Enjoy,
Tony

www.WordArticles.com

I search the text in a range.... on macro i set to search the text in a
selection of 3 lines

selection.movedown unit:=wdparagraph, count:=3, extend:=wdextend
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[a-z0-9]@[:;, ]@[A-Z a-z.]@[,^13-]@[ ^13R.Gg.]@[0-9
..X-]@[,^13]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True ---> i try in false mode
.MatchCase = False
.MatchWholeWord = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchWildcards = True
End With
Selection.Find.Execute

the bug persists..... =/
 
T

Tony Jollans

There's nothing obviously wrong, but it is a slightly complex pattern. Can
you post the Selection text that you are looking at?

--
Enjoy,
Tony

www.WordArticles.com

Devacann said:
Tony Jollans said:
Selection.Find remembers settings within a Word session.

If, perhaps, someone has done a Find looking for formatted text in the
UI,
and then you look for your text without resetting all the options, your
text
may not be found.

Much better to use your own Range - its Find object will be initialised
to
all default options when you create the Range.

--
Enjoy,
Tony

www.WordArticles.com

I search the text in a range.... on macro i set to search the text in a
selection of 3 lines

selection.movedown unit:=wdparagraph, count:=3, extend:=wdextend
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[a-z0-9]@[:;, ]@[A-Z a-z.]@[,^13-]@[ ^13R.Gg.]@[0-9
.X-]@[,^13]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True ---> i try in false mode
.MatchCase = False
.MatchWholeWord = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchWildcards = True
End With
Selection.Find.Execute

the bug persists..... =/
 
P

Pesach Shelnitz

Hi,

I think that your problem could be avoided by calling Find on a separate
Range object. Try this.

Sub TryMe()
Dim myRange As Range

Selection.MoveDown unit:=wdParagraph, Count:=3, Extend:=wdExtend
Set myRange = Selection.Range
Selection.Collapse Direction:=wdCollapseStart
With myRange.Find
.Text = "[a-z0-9]@[:;,]@[A-Z a-z.]@[,^13-]@[
^13R.Gg.]@[0-9.X-]@[,^13]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True
End With
If myRange.Find.Execute = True Then
myRange.Select
End If
End Sub

--
Hope this helps,
Pesach Shelnitz


Tony Jollans said:
There's nothing obviously wrong, but it is a slightly complex pattern. Can
you post the Selection text that you are looking at?

--
Enjoy,
Tony

www.WordArticles.com

Devacann said:
Tony Jollans said:
Selection.Find remembers settings within a Word session.

If, perhaps, someone has done a Find looking for formatted text in the
UI,
and then you look for your text without resetting all the options, your
text
may not be found.

Much better to use your own Range - its Find object will be initialised
to
all default options when you create the Range.

--
Enjoy,
Tony

www.WordArticles.com

I search the text in a range.... on macro i set to search the text in a
selection of 3 lines

selection.movedown unit:=wdparagraph, count:=3, extend:=wdextend
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[a-z0-9]@[:;, ]@[A-Z a-z.]@[,^13-]@[ ^13R.Gg.]@[0-9
.X-]@[,^13]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True ---> i try in false mode
.MatchCase = False
.MatchWholeWord = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchWildcards = True
End With
Selection.Find.Execute

the bug persists..... =/
 
D

Devacann

Pesach Shelnitz said:
Hi,

I think that your problem could be avoided by calling Find on a separate
Range object. Try this.

Sub TryMe()
Dim myRange As Range

Selection.MoveDown unit:=wdParagraph, Count:=3, Extend:=wdExtend
Set myRange = Selection.Range
Selection.Collapse Direction:=wdCollapseStart
With myRange.Find
.Text = "[a-z0-9]@[:;,]@[A-Z a-z.]@[,^13-]@[
^13R.Gg.]@[0-9.X-]@[,^13]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True
End With
If myRange.Find.Execute = True Then
myRange.Select
End If
End Sub

--
Hope this helps,
Pesach Shelnitz


Tony Jollans said:
There's nothing obviously wrong, but it is a slightly complex pattern. Can
you post the Selection text that you are looking at?

--
Enjoy,
Tony

www.WordArticles.com




YEAH!!! Thanks... ^^
The search has function perfectly....
 

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