Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-17-2017, 12:22 PM
qubie qubie is offline Wild Card Problem (Word 2007) Windows 7 64bit Wild Card Problem (Word 2007) Office 2007
Novice
Wild Card Problem (Word 2007)
 
Join Date: Aug 2016
Posts: 24
qubie is on a distinguished road
Default Wild Card Problem (Word 2007)

Greetings,

I am having trouble with "^13" in a wild card macro with which I am working.

I am applying the macro to search through text that has - scattered throughout - collections of numbers that are separated by two dashes, e.g., "4-5-708". These patterns in the text are not identical; in other words, within a single record, I may find "55-1-1" as well as "55-11-111", as well as "5-1-111", and so on.

I am interested in highlighting each collection of numbers, if any, that begins a paragraph of text.

Here is a brief snippet from the macro that is supposed to look for, e.g., "4-5-201" at the beginning of a text paragraph, highlight it, and add bold font to it:

Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Bold = True
Selection.Find.Replacement.Highlight = True


With Selection.Find
.Text = "^13[0-9]-[0-9]-[0-9]{2,3}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

My difficulty is that the foregoing does not work; it should, but it does not. I believe the culprit is "^13", but I am unable to find a working equivalent or work-around.

When I search the record for "[0-9]-[0-9]-[0-9]{2,3}", I get results, but this search is not confined only to patterns that lead a paragraph of the content.

When I wild-card-search the record for "^13", I also get results; indeed, Word appears to land upon the hard returns that precede the number patterns of interest.

When I make use of "^p" and a literal number that I know is in the text (e.g., "4-5-790"), I also get results.

When, however, I undertake to use "^13[0-9]-[0-9]-[0-9]{2,3}", Word finds nothing in the record. That is odd to me, but perhaps I am missing something.

I appreciate your attention and hope you may have suggestions.

Regards,

q.
Reply With Quote
  #2  
Old 10-17-2017, 02:05 PM
macropod's Avatar
macropod macropod is offline Wild Card Problem (Word 2007) Windows 7 64bit Wild Card Problem (Word 2007) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

The following works fine for me for reformatting all of your number forms in one go:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Replacement.Font.Bold = True
    .Replacement.Highlight = True
    .Text = "^13[0-9]{1,}-[0-9]{1,}-[0-9]{1,}"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-19-2017, 04:18 AM
qubie qubie is offline Wild Card Problem (Word 2007) Windows 7 64bit Wild Card Problem (Word 2007) Office 2007
Novice
Wild Card Problem (Word 2007)
 
Join Date: Aug 2016
Posts: 24
qubie is on a distinguished road
Default

Thanks for your insight. I co-opted the bold portion of the coding below --

^13[0-9]{1,}-[0-9]{1,}-[0-9]{1,}

-- and it is really useful; thanks for that.

When I run the macro I still find, however, that the component "^13" in the expression is not being recognized in the content. I have now tested this in Word 2007 and also Word 2003, with the same results.

I created a work-around that does not use "^13" in the above expression, and I believe this may work for most cases. I remain unclear, however, why the expression above is not working when "^13" leads it.

Thanks again,

q.

Last edited by qubie; 10-19-2017 at 04:19 AM. Reason: clarification
Reply With Quote
  #4  
Old 10-19-2017, 05:44 AM
macropod's Avatar
macropod macropod is offline Wild Card Problem (Word 2007) Windows 7 64bit Wild Card Problem (Word 2007) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

The wildcard expression I posted will work in all Word versions, with or without a macro on PCs and Macs alike. If it's not working with your data, that suggests they are not as described. Maybe you have a tab or no-width non-breaking space in between the paragraph break and the string you're after.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 10-19-2017, 06:17 AM
qubie qubie is offline Wild Card Problem (Word 2007) Windows 7 64bit Wild Card Problem (Word 2007) Office 2007
Novice
Wild Card Problem (Word 2007)
 
Join Date: Aug 2016
Posts: 24
qubie is on a distinguished road
Default

Paul,

I figured as much, but what I cannot seem to find is a wild card representation for "odd" breaks within the content with which I am working. I recall coming across such creatures once upon a time in passing, but I cannot cull them forth on this occasion.

In efforts to cut to the chase, I attached a representation of what I am talking about; I think that, just perhaps, this depicts the no-width non-breaking space that you mentioned. The pattern recurs throughout the data set. My work-around is serviceable, but a bit clunky.

At any rate, your suggestion pushed my effort forward significantly -- I appreciate that very much.

q.
Attached Files
File Type: doc Word_Forum_Macros_Question.doc (25.5 KB, 10 views)
Reply With Quote
  #6  
Old 10-19-2017, 06:19 AM
macropod's Avatar
macropod macropod is offline Wild Card Problem (Word 2007) Windows 7 64bit Wild Card Problem (Word 2007) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

An image is of no use for diagnostic purposes; one would need access to the actual content.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
macros don't work, word 2007

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use wild card in VBA for Advance Filter? LearnerExcel Excel Programming 1 10-09-2017 12:27 AM
Wild Card Problem (Word 2007) find with wild cards and add into CC sylvio Word VBA 2 09-04-2017 01:00 AM
Wild Card Problem (Word 2007) Question about find and replace wild cards catherineliang Word 1 07-21-2014 09:42 PM
Wild card to highlight capitalised terms? bertietheblue Word 2 02-08-2013 04:44 PM
Wild Card Problem (Word 2007) Problem saving in Word 2007 a dotm Addin developed in Word 2010 RichardP Word VBA 6 04-26-2012 04:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:50 PM.


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