andrewdavies
12-20-2016, 10:02 AM
Hi all,
I'm new to posting to this site (but have used many pieces of code!) but I've come unstuck with VBA and need your help!
Essentially what I'm trying to do is go through a document and search for text of a particular font and delete said text, apart from in certain cases i.e. when the text line contains the word 'COLUMNS' or 'ROWS' for example. I'm tinkering with the below code, but need to set up these exclusions.
Thanks in advance!
Sub Demo()Dim lngColor As Long
Application.ScreenUpdating = False
lngColor = Selection.Range.Font.Color
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Color = lngColor
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub
I'm new to posting to this site (but have used many pieces of code!) but I've come unstuck with VBA and need your help!
Essentially what I'm trying to do is go through a document and search for text of a particular font and delete said text, apart from in certain cases i.e. when the text line contains the word 'COLUMNS' or 'ROWS' for example. I'm tinkering with the below code, but need to set up these exclusions.
Thanks in advance!
Sub Demo()Dim lngColor As Long
Application.ScreenUpdating = False
lngColor = Selection.Range.Font.Color
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Color = lngColor
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub