PDA

View Full Version : Find string within word document



lamnbj
05-10-2022, 08:01 AM
I have categories like:
a, Content.
a. Content:
a, Content:
I tried the following code with no success


Sub A123()

On Error Resume Next

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Bold = True
.Color = wdColorBlue
End With
With Selection.Find
.text = "(a[,\.] Noi dung)([.:])"
.Replacement.text = "a) Noi dung"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub


Sorry my English is very bad. Thank you

Paul_Hossler
05-10-2022, 09:44 AM
1. I added CODE tags to your macro to format it

2. Not exactly sure what you're looking to do, but based on looking at the macro, this seems to find 'Noi dung' and makes it blue




Option Explicit


Sub A123()

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting

With .Replacement.Font
.Bold = True
.Color = wdColorBlue
End With


.Text = "(a[,\.] Noi dung)([.:])"
.Replacement.Text = "a) Noi dung\2"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll

End With
End Sub

lamnbj
05-10-2022, 05:37 PM
Ok. Thank you very much

Paul_Hossler
05-12-2022, 09:15 AM
Ok. Thank you ...

BTW, it's not necessary to include the entire post in a [Reply With Quote]

You can edit the material to just what you need to reference, so you didn't need the macro

It just makes a post easier to read is all :thumb