Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-19-2019, 10:32 AM
MikeForward MikeForward is offline Problems with wildcard search VBA Windows 10 Problems with wildcard search VBA Office 2010
Novice
Problems with wildcard search VBA
 
Join Date: Feb 2019
Posts: 10
MikeForward is on a distinguished road
Default Problems with wildcard search VBA

Hi there,



I am getting very odd results with the following wildcard search in VBA
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[.,;:-\?\!^13^34]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute

The intention was to find any of these characters:
. , ; : - ? ! [CR] and "

However, this search is also finding the "=" sign, even though its not in the list of search characters I have requested! Any ideas? I suspect I have encountered numerous similar instabilities in Selection.Find in Word. Does this function have documented issues?

As an aside, is it ok to put ^n1^n2^n3 ... in order to search for ascii characters n1, n2, n3 ...

Thanks

Mike
Reply With Quote
  #2  
Old 02-19-2019, 01:28 PM
macropod's Avatar
macropod macropod is offline Problems with wildcard search VBA Windows 7 64bit Problems with wildcard search VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Because of :-\?, your Find expression say, amongst other things, to find all characters between : and ?. That includes :, ;, <, =, >, and ?. You need to use \-, as in:
.Text = "[.,;:\-\?\!^13^34]"
And, yes, you can use ^n, where n is a number, to look for ASCII characters - but for the most part you can also use the characters themselves.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-19-2019, 02:38 PM
MikeForward MikeForward is offline Problems with wildcard search VBA Windows 10 Problems with wildcard search VBA Office 2010
Novice
Problems with wildcard search VBA
 
Join Date: Feb 2019
Posts: 10
MikeForward is on a distinguished road
Default

Awesome, thanks. So I put - and should have put \- since - is a special character

Thanks a lot

Mike

PS: Do I need to mark this as solved?
Reply With Quote
  #4  
Old 02-19-2019, 03:23 PM
macropod's Avatar
macropod macropod is offline Problems with wildcard search VBA Windows 7 64bit Problems with wildcard search VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by MikeForward View Post
Do I need to mark this as solved?
Done & dusted.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
wildcard searches

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with wildcard search VBA Wildcard search once worked, now does not Peterson Word 2 09-17-2018 07:17 AM
Problems with wildcard search VBA Having problems with a Wildcard search Cosmo Word VBA 9 02-12-2016 08:03 PM
Issue with wildcard search mysterytramp Word 0 05-13-2015 10:40 AM
Where is the error in my wildcard search? Ulodesk Word 10 06-30-2014 01:46 PM
Wildcard search help. Kempston Word 0 11-13-2009 03:58 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft