C
christophercbrewster via OfficeKB.com
I wrote the following code, which seemed so obvious that I wasn't expecting
it to fail. But for some reason, the step that searches for a style fails.
The string value, such as "List Continue 2" matches a style name in the
template. If I use a literal string value (such as the one just shown), the
statement works. So the use of the string variable is causing a problem. One
more detail: the statement works correctly when the string variable is "List
Continue". So the problem is related to the use of the digit characters. Any
suggestions appreciated.
This routine is called from another routine...
Public sLevel As String
------------------------------------
Sub ReplaceContinues()
'
Dim sConLevel As String, sFindStyle As String
For nConLevel = 1 To 5
If Not nConLevel = 1 Then
sConLevel = " " + Str(nConLevel)
Else
sConLevel = ""
End If
Selection.Find.ClearFormatting
sFindStyle = "List Continue" + sConLevel
' This statement doesn't work:
Selection.Find.Style = ActiveDocument.Styles(sFindStyle)
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("List
Continue" + sLevel)
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub
--
Christopher Brewster
Lockheed Martin, Eagan MN
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200906/1
it to fail. But for some reason, the step that searches for a style fails.
The string value, such as "List Continue 2" matches a style name in the
template. If I use a literal string value (such as the one just shown), the
statement works. So the use of the string variable is causing a problem. One
more detail: the statement works correctly when the string variable is "List
Continue". So the problem is related to the use of the digit characters. Any
suggestions appreciated.
This routine is called from another routine...
Public sLevel As String
------------------------------------
Sub ReplaceContinues()
'
Dim sConLevel As String, sFindStyle As String
For nConLevel = 1 To 5
If Not nConLevel = 1 Then
sConLevel = " " + Str(nConLevel)
Else
sConLevel = ""
End If
Selection.Find.ClearFormatting
sFindStyle = "List Continue" + sConLevel
' This statement doesn't work:
Selection.Find.Style = ActiveDocument.Styles(sFindStyle)
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("List
Continue" + sLevel)
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub
--
Christopher Brewster
Lockheed Martin, Eagan MN
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200906/1