Mark was telling us:
Mark nous racontait que :
Many thanks for your help.
The following seems to run, but does not change anything. I.e. Main
Text * are not changing to "Main Text." The other problem is that it
complains about "s.NameLocal = "Main Text"" as Main Text already
exists. Is there a way to replace Main Text * with Main Text. What am
I doing wrong?
Mark
Sub Find_Replace_MainT()
Dim pIndex As Long
For pIndex = ActiveDocument.Styles.Count To 1 Step -1
Set s = ActiveDocument.Styles(pIndex)
If Left$(s.NameLocal, 10) = "Main Text " Then
s.NameLocal = "Main Text"
Exit For
End If
Next
End Sub
Try this and see my comments in the beginner group (I think it was the
beginner group...):
'_______________________________________
Sub Find_Replace_MainT()
Dim pIndex As Long
Dim MyStyle As Style
Const TempStyleName As String = "TempStyle"
Const RegularName As String = "Main Text"
'Save any paragraph where the Normal style is applied
With ActiveDocument
.Styles.Add TempStyleName
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles("Normal")
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
With .Replacement
.ClearFormatting
.Style = ActiveDocument.Styles(TempStyleName)
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
'Delete all Char styles derived from Main Text
'Paragraphs where a deleted style was applied will
'revert to the Normal style
For pIndex = .Styles.Count To 1 Step -1
Set MyStyle = .Styles(pIndex)
With MyStyle
If Left$(.NameLocal, 10) = RegularName & " " Then
.Delete
End If
End With
Next
'Apply Main Text to all Normal paragraphs
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles("Normal")
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
With .Replacement
.ClearFormatting
.Style = ActiveDocument.Styles(RegularName)
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
'Delete the TempStyle style and if any pargraph were formatted
'with it, they will be returned to their original "Normal" style
.Styles(TempStyleName).Delete
End With
End Sub
'_______________________________________
Please, try not to ask the same questions in many places, If my code here is
sufficient, why should Jezebel waste time writing an answer that will be
ignored. And vice versa, if Jezebel had replied before I did, you might have
totally ignored my answer in the other group and thus I would have ended up
wasting time for nothing...
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org