VBA ".Wrap = FindAsk" does not work within a For Next Loop

G

GlennMc

I copied a macro from my normal.dot to another user's computer, but the .Wrap
statement is ignored within the For Next Loop when I run the macro on their
computer. Why would it work on mine and not theirs?
 
J

Jean-Guy Marcil

GlennMc was telling us:
GlennMc nous racontait que :
I copied a macro from my normal.dot to another user's computer, but
the .Wrap statement is ignored within the For Next Loop when I run
the macro on their computer. Why would it work on mine and not theirs?

Show us your code.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

GlennMc

Selection.HomeKey Unit:=wdStory

' Find and delete duplicate index fields

For X = 1 To 2500
Selection.Find.ClearFormatting
With Selection.Find
.Text = " XE "
.Forward = True
.Wrap = wdFindAsk
'.Format = True
'.MatchCase = False
'.MatchWholeWord = False
'.MatchWildcards = False
'.MatchSoundsLike = False
'.MatchAllWordForms = False

End With

Selection.Find.Execute
Selection.Extend Character:=""""
Selection.Extend Character:=""""

With Selection

Word1 = Selection
If Word1 = Word3 Then

Selection.Delete
Selection.EndKey Unit:=wdLine
Else
Selection.EndKey Unit:=wdLine

End If
End With

Selection.Find.Execute

Selection.Extend Character:=""""
Selection.Extend Character:=""""
With Selection
Word2 = Selection

End With

If Word1 = Word2 Then
Selection.Delete
Word3 = Word2
Else
Word3 = Word2
Selection.EndKey Unit:=wdLine

End If

Next
 
J

Jean-Guy Marcil

GlennMc was telling us:
GlennMc nous racontait que :
Selection.HomeKey Unit:=wdStory

' Find and delete duplicate index fields

For X = 1 To 2500

Why this arbitrary statement? Why 2500?
Selection.Find.ClearFormatting
With Selection.Find
.Text = " XE "

I guess there is some missing code otherwise, as is, XE may not be found if
hidden text is not shown.
.Forward = True
.Wrap = wdFindAsk
'.Format = True
'.MatchCase = False
'.MatchWholeWord = False
'.MatchWildcards = False
'.MatchSoundsLike = False
'.MatchAllWordForms = False

End With

Selection.Find.Execute

I do not understand the purpose of these two lines of code:
Selection.Extend Character:=""""
Selection.Extend Character:=""""

With Selection

Word1 = Selection
If Word1 = Word3 Then

Selection.Delete
Selection.EndKey Unit:=wdLine
Else
Selection.EndKey Unit:=wdLine

End If
End With

Selection.Find.Execute

Selection.Extend Character:=""""
Selection.Extend Character:=""""
With Selection
Word2 = Selection

End With

If Word1 = Word2 Then
Selection.Delete
Word3 = Word2
Else
Word3 = Word2
Selection.EndKey Unit:=wdLine

End If

Next

I think you forgot to show us all the relevant code, or, if not, this code
as is, may not work all the time.
Also, you never explained what you expected from
.Wrap = wdFindAsk

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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