I am trying to delete everything in a specific word document that is highlighted in a certain color, in this example; wdYellow. I have some code below that opens the Word document, tries to find where highlighting occurs and deletes it accordingly.
Set wrdApp = New Word.Application
strFilePath = ThisWorkbook.Path
Set wrdDoc = wrdApp.Documents.Add(strFilePath & "\test.docx")
With wrdDoc.Content.Find
If .Highlight = wdYellow Then
.text = ""
End If
End With
wrdDoc.SaveAs (strFilePath & "\test.docx")
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing
So this code works to an extent... It doesn't actually find any highlights with wdYellow, so it will never reach .text = "". But other than that, it runs through it just fine. I believe the error to be with the With wrdDoc.Content.Find section. Can anyone help me out?
finddoesn't work withIfin this manner. I suggest you try in the Word UI (Ctrl+H) to find the highlight color and record a macro to get the basics. Also, you can try usingReplaceand replace with nothing (empty string - no entry in the Replace box). Not sure whether that will work with highlighting, though... If it doesn't work, get as far as you can based on the recorded macro, then update your post with that and describe how it's not doing the job. - Cindy Meister