Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

VBA error with Find Command using wildcards.

1 réponse
Avatar
xavier.godin
I am facing an error with the following case. I do a find
on a specific pattern :

"<[A-Z_]@/[A-Z]@/[0-9_.]@>"

. The Goal of the macro.
The macro should display the 4 expressions AQ/. Due to
the presence of the Hyperlink, it does not print the
fourth.



Copy the following text in a new document. Add the
hyperlink in the second paragraph. Then copy the macro
code in VBA and run it. You will receive 4 messages, the
fourth being empty (problme with the hyperlink). You will
not receive a message for the last AQ/....

<start_of_text>

1.1. Paragraph without Hyperlink, the macro finds all
the blue links.
We want to cath this pattern AQ/BNB/03.

If there is no hyperlink here
http://info.ev.siemens.de/ev_ga/pm-siemens/EN/INDEX.HTML
we also find this one AQ/BNB/04.


1.2. Paragraph with Hyperlink, the macro stops after
the external link.
We want to cath this pattern AQ/BNB/03.

If there is an hyperlink here
http://info.ev.siemens.de/ev_ga/pm-siemens/EN/INDEX.HTML
then we do not find this one AQ/BNB/04.

<end of text>


3. The code
Sub Bug2002()

Dim SelectedText As String

Selection.Find.ClearFormatting
Selection.HomeKey Unit:=wdStory

With Selection.Find
.Text = "<[A-Z_]@/[A-Z]@/[0-9_.]@>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

While Selection.Find.Execute

SelectedText = Trim(Selection.Text)
MsgBox ("<" + SelectedText + ">")

Wend

End Sub

1 réponse

Avatar
Guy Moncomble
Bonjour à tous,
dans le message 7f3701c431a4$eb7c3580$,

| I am facing an error with the following case. I do a find
| on a specific pattern :
|
| "<[A-Z_]@/[A-Z]@/[0-9_.]@>"
|
| . The Goal of the macro.
| The macro should display the 4 expressions AQ/. Due to
| the presence of the Hyperlink, it does not print the
| fourth.
|
|
|
| Copy the following text in a new document. Add the
| hyperlink in the second paragraph. Then copy the macro
| code in VBA and run it. You will receive 4 messages, the
| fourth being empty (problme with the hyperlink). You will
| not receive a message for the last AQ/....
|
| <start_of_text>
|
| 1.1. Paragraph without Hyperlink, the macro finds all
| the blue links.
| We want to cath this pattern AQ/BNB/03.
|
| If there is no hyperlink here
| http://info.ev.siemens.de/ev_ga/pm-siemens/EN/INDEX.HTML
| we also find this one AQ/BNB/04.
|
|
| 1.2. Paragraph with Hyperlink, the macro stops after
| the external link.
| We want to cath this pattern AQ/BNB/03.
|
| If there is an hyperlink here
| http://info.ev.siemens.de/ev_ga/pm-siemens/EN/INDEX.HTML
| then we do not find this one AQ/BNB/04.
|
| <end of text>
|
|
| 3. The code
| Sub Bug2002()
|
| Dim SelectedText As String
|
| Selection.Find.ClearFormatting
| Selection.HomeKey Unit:=wdStory
|
| With Selection.Find
| .Text = "<[A-Z_]@/[A-Z]@/[0-9_.]@>"
| .Replacement.Text = ""
| .Forward = True
| .Wrap = wdFindContinue
| .Format = False
| .MatchCase = False
| .MatchWholeWord = False
| .MatchWildcards = True
| .MatchSoundsLike = False
| .MatchAllWordForms = False
| End With
|
| While Selection.Find.Execute
|
| SelectedText = Trim(Selection.Text)
| MsgBox ("<" + SelectedText + ">")
|
| Wend
|
| End Sub

Non seulement tu t'exprimes en anglais dans un groupe .fr, mais tu crois
pouvoir te passer de bonjour et d'au-revoir. Pourquoi voudrais-tu que
l'on te réponde autre chose que : une réponse possible est dans la
question ? De plus chez moi un lien hypertexte valide n'arrête pas la
recherche.
--
A+

G.M. MVP Word