Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-27-2021, 11:28 PM
LQuinn LQuinn is offline find/replace wildcard expression help Windows 10 find/replace wildcard expression help Office 2019
Novice
find/replace wildcard expression help
 
Join Date: Jan 2021
Location: Western Australia
Posts: 20
LQuinn is on a distinguished road
Default find/replace wildcard expression help

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
Reply With Quote
  #2  
Old 01-28-2021, 01:05 AM
macropod's Avatar
macropod macropod is offline find/replace wildcard expression help Windows 10 find/replace wildcard expression help Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,373
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

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]
Reply With Quote
  #3  
Old 01-28-2021, 11:57 PM
LQuinn LQuinn is offline find/replace wildcard expression help Windows 10 find/replace wildcard expression help Office 2019
Novice
find/replace wildcard expression help
 
Join Date: Jan 2021
Location: Western Australia
Posts: 20
LQuinn is on a distinguished road
Default

Thank you so much Paul, very much appreciated!
Reply With Quote
Reply



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
find/replace wildcard expression help Wildcard Find and Replace anomaly BruceM Word 3 07-10-2015 04:33 AM
find/replace wildcard expression help New Find/Replace Wildcard Needed rsrasc Word VBA 2 11-11-2014 09:46 AM
find/replace wildcard expression help Wildcard Find and Replace Ulodesk Word 1 06-23-2014 10:26 AM
find/replace wildcard expression help Need help using WildCard Find & Replace Cayce Word 1 06-09-2014 04:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:03 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