J
JS
Hi all,
I've bumped into an interesting challenge - how to delete all text in a file
except certain types of formatted text. I came up with a VBA solution (only
for highlighted text) [conde listed below], but it is clumsy, unelegent and
SOOOOO SLOOOOW [can take hours!!!]....
Does anyone have a better idea/solution they might want to share?
Thanks in advance for your help!!! Rgds, JS
=============================
Sub DeleteALLWordsEXCEPTHighlight()
Dim xxx As Long
' need to set all paragraph marks to highlighted, otherwise they are deleted
below
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = True
With Selection.Find
.Text = "^p"
.Replacement.Text = "^p"
.Forward = False
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'
Selection.WholeStory
For xxx = Selection.Words.Count To 2 Step -1
If Selection.Words(xxx).HighlightColorIndex <> wdYellow Then ' note:
Words(xxx) also bring paragraph marks!!!
' MsgBox Selection.Words(xxx)
Selection.Words(xxx).Select
Selection.Delete
Selection.WholeStory
End If
Next
End Sub
========================================
I've bumped into an interesting challenge - how to delete all text in a file
except certain types of formatted text. I came up with a VBA solution (only
for highlighted text) [conde listed below], but it is clumsy, unelegent and
SOOOOO SLOOOOW [can take hours!!!]....
Does anyone have a better idea/solution they might want to share?
Thanks in advance for your help!!! Rgds, JS
=============================
Sub DeleteALLWordsEXCEPTHighlight()
Dim xxx As Long
' need to set all paragraph marks to highlighted, otherwise they are deleted
below
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = True
With Selection.Find
.Text = "^p"
.Replacement.Text = "^p"
.Forward = False
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'
Selection.WholeStory
For xxx = Selection.Words.Count To 2 Step -1
If Selection.Words(xxx).HighlightColorIndex <> wdYellow Then ' note:
Words(xxx) also bring paragraph marks!!!
' MsgBox Selection.Words(xxx)
Selection.Words(xxx).Select
Selection.Delete
Selection.WholeStory
End If
Next
End Sub
========================================