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:
- TA8X.0100185.S14.03EN
- TA8X.0100185.D07.24EN
- TA8X.0100184.S14.00EN
- TA8X.0100185.D07.01EN
- TA8X.0100185.D07.06EN
- 109E.0101548.D03.00EN
- 109E.0101549.D03.00EN
- 109E.0101552.D03.00EN
- 90000199.L03.EN
- SWMS-BE-ETCS-GEN-58
- SWMS-BE-ETCS-GEN-61
- SWMS-BE-ETCS-GEN-63
- TA8X.0100185.D07.04EN
- TA8X.0100184.A07.00EN
- B63E.0100030.D01.00EN
- B63E.0100029.D02.00EN
- B63E.0100029.D02.00EN
- TA8X.0100185.D07EN
- TA8X.0100185.D07.02EN REV 01.00
- TA8X.0100185.D07.00EN REV 01.00
- TA8X.0100185.D07.12EN REV 00.00
- TA8X.0100XXX.D07.02EN REV 00.00
- P12E.0100086.D02.00EN
- B60A.0100655.D02.00EN
- B60A.0100650.D02.00EN
- B60A.0100653.D02.EN
- B60A.0100656.D02.00EN
- B60A.0100657.D02.00EN
- B63E.0100040D01.00EN
- B60A.0100667.D02.00EN
- TA8X.0100185.L03.00EN.
- TA8X.0100185.D07.
- B631.0100007.D02.00EN.
- B631.0100009.D02.00EN.
- TA8X.0100185.L03.00EN
- TA8X.0100185.D07.17EN.
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