D
Dan
Hello All,
I'm slowly but surely gaining an education into at least the basics of
writing macros. I've got something that is pretty close to what I want,
but not quite there.
I've got a bunch of documents that have step numbers manually entered.
These steps should always be in one of four styles. So I put together a
macro that looks at the style and then searches for wildcard text that
should related to the step numbers and the following tab, and replaces
them with nothing.
It mostly worked, but would occasionally delete some other text that I
didn't want to delete in some of the lines.
Now I know the step numbers are always the first thing on a line, so I
added a paragraph mark to my wildcard text string. I figured that would
ensure it would only look for the numbers that follow a return.
However, when I added the paragraph mark to the .Text and
..ReplacementText entries, my macro gets stuck in a loop between "Do
While . . ." and "Loop". Entries.
Am I going about this the wrong way, or am I just making an ignorant
mistake?
Any help will be greatly appreciated!
Dan
---
Sub MacroName()
Dim FindStyle As Variant, k As Integer
FindStyle = Array("Para 1.1", "Para 1.1.1", "Para 1.1.1.1", "Para
1.1.1.1.1")
On Error Resume Next
For k = 0 To 3
With ActiveDocument.Range.Find
..ClearFormatting
..Replacement.ClearFormatting
..Text = "^p[1-9].*[1-9]^t"
..Replacement.Text = "^p"
..Format = True
..MatchWildcards = True
..Style = FindStyle(k)
Do While .Execute(Replace:=wdReplaceAll)
Loop
End With
Next
End Sub
I'm slowly but surely gaining an education into at least the basics of
writing macros. I've got something that is pretty close to what I want,
but not quite there.
I've got a bunch of documents that have step numbers manually entered.
These steps should always be in one of four styles. So I put together a
macro that looks at the style and then searches for wildcard text that
should related to the step numbers and the following tab, and replaces
them with nothing.
It mostly worked, but would occasionally delete some other text that I
didn't want to delete in some of the lines.
Now I know the step numbers are always the first thing on a line, so I
added a paragraph mark to my wildcard text string. I figured that would
ensure it would only look for the numbers that follow a return.
However, when I added the paragraph mark to the .Text and
..ReplacementText entries, my macro gets stuck in a loop between "Do
While . . ." and "Loop". Entries.
Am I going about this the wrong way, or am I just making an ignorant
mistake?
Any help will be greatly appreciated!
Dan
---
Sub MacroName()
Dim FindStyle As Variant, k As Integer
FindStyle = Array("Para 1.1", "Para 1.1.1", "Para 1.1.1.1", "Para
1.1.1.1.1")
On Error Resume Next
For k = 0 To 3
With ActiveDocument.Range.Find
..ClearFormatting
..Replacement.ClearFormatting
..Text = "^p[1-9].*[1-9]^t"
..Replacement.Text = "^p"
..Format = True
..MatchWildcards = True
..Style = FindStyle(k)
Do While .Execute(Replace:=wdReplaceAll)
Loop
End With
Next
End Sub