![]() |
|
#1
|
|||
|
|||
|
Hi all, new to wildcards/expressions and looking for some help please
Where I work we have a document control system that generates unique document IDs as follows:
I'm trying to find and format based on wildcards in find/replace, but Word is generating a 'pattern match too complex' error message if I add this for 'SWMS' "<([A-Z]{4}[-])([A-Z]{2}[-])([A-Z]{4}[-])([A-Z]{3}[-])([0-9]{2})>" hoping this is enough detail for someone to point me in the right direction please! Code:
Private Sub Tools_Text_Format_TeamCenter_Document_Numbers()
'
' find teamcenter document numbers and format them
'
' https://regex101.com/
'
Dim arrFindReplaceExpressions()
Dim varCounter As Variant
arrFindReplaceExpressions = Array("<([0-9A-Z]{4}[.])([0-9A-Z]{7}[.])([0-9A-Z]{3}[.])([0-9A-Z.]{4})>", _
"<([0-9A-Z]{4}[.])([0-9A-Z]{7}[.])([0-9A-Z]{3}[.])([0-9A-Z.]{2})>", _
"<([0-9]{8}[.])([0-9A-Z]{3}[.])([A-Z]{2})>")
For Each varCounter In arrFindReplaceExpressions
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
'.Replacement.Text = ""
.Text = varCounter
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True ' needed for special characters, otherwise they're treated as ordinary text
.Execute Replace:=wdReplaceAll
End With
Next varCounter
Set varCounter = Nothing
Erase arrFindReplaceExpressions
Debug.Print "Finished!"
End Sub
|
|
#2
|
||||
|
||||
|
Perhaps:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "<[A-Z0-9.\-]@[A-Z0-9.\-]@[DE]*>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
End With
Do While .Find.Execute
Set Rng = .Duplicate
With Rng
.End = .Paragraphs(1).Range.End - 1
.End = .Start + Len(Split(.Text, " ")(0))
.Collapse wdCollapseEnd
.End = .Paragraphs(1).Range.End - 1
If UBound(Split(.Text, " ")) > 1 Then
If Split(.Text, " ")(1) = "REV" Then .End = .Start + 10
End If
End With
.End = Rng.End
.Font.Bold = True
.Collapse wdCollapseEnd
Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thank you so much Paul, very much appreciated!
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Help With Find and Replace Wildcard | rsrasc | Word VBA | 9 | 10-13-2015 02:37 PM |
Wildcard Find and Replace anomaly
|
BruceM | Word | 3 | 07-10-2015 04:33 AM |
New Find/Replace Wildcard Needed
|
rsrasc | Word VBA | 2 | 11-11-2014 09:46 AM |
Wildcard Find and Replace
|
Ulodesk | Word | 1 | 06-23-2014 10:26 AM |
Need help using WildCard Find & Replace
|
Cayce | Word | 1 | 06-09-2014 04:17 PM |