B
Budget Programmer
Hello,
I'm a little bit new to Word VBA. Been working with Excel VBA for a while.
I built the following macro to delete text that had the style of
"Instructions" applied to it. The idea is for the user to execute this after
they're done filling out the document.
For the most part, it works well. There are a couple of problems however.
If the instructions are immediately followed by a table, inserted JPG, etc.
it doesn't delete the preceeding text. It could be a single space, a line of
text, whatever. The issue is when the text (styled with "Instructions")
immediately preceeds something WITHOUT a hard return, it doesn't get deleted.
Please give me some guidance. I appreciate your help.
Sub Test2()
Dim objDocumentRange As Range
Dim strTargetStyle As String
Dim strResultText As String
strTargetStyle = "Instructions"
strResultText = ""
Set objDocumentRange = ActiveDocument.Range
With objDocumentRange.Find
.Style = strTargetStyle
.MatchAllWordForms = True
.Text = strResultText
.Execute Replace:=wdReplaceAll
End With
End Sub
I'm a little bit new to Word VBA. Been working with Excel VBA for a while.
I built the following macro to delete text that had the style of
"Instructions" applied to it. The idea is for the user to execute this after
they're done filling out the document.
For the most part, it works well. There are a couple of problems however.
If the instructions are immediately followed by a table, inserted JPG, etc.
it doesn't delete the preceeding text. It could be a single space, a line of
text, whatever. The issue is when the text (styled with "Instructions")
immediately preceeds something WITHOUT a hard return, it doesn't get deleted.
Please give me some guidance. I appreciate your help.
Sub Test2()
Dim objDocumentRange As Range
Dim strTargetStyle As String
Dim strResultText As String
strTargetStyle = "Instructions"
strResultText = ""
Set objDocumentRange = ActiveDocument.Range
With objDocumentRange.Find
.Style = strTargetStyle
.MatchAllWordForms = True
.Text = strResultText
.Execute Replace:=wdReplaceAll
End With
End Sub