K
k2000s
Hi,
New to VBA (today)! Recorded 2 macros: T1 find/replace text and CS1
find/replace style. Both runs fine during After recording and running tools >
macro > macros > xx > run, only T1 works but CS1 does nothing.
What step am I missing or are there restrictions on changing styles with
a macro?
- k2ks
Sub T1()
'
' T1 Macro
' Macro recorded 7/17/2008
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Hello"
.Replacement.Text = "Hello2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub CS1()
'
' CS1 Macro
' Macro recorded 7/17/2008
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading2")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
New to VBA (today)! Recorded 2 macros: T1 find/replace text and CS1
find/replace style. Both runs fine during After recording and running tools >
macro > macros > xx > run, only T1 works but CS1 does nothing.
What step am I missing or are there restrictions on changing styles with
a macro?
- k2ks
Sub T1()
'
' T1 Macro
' Macro recorded 7/17/2008
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Hello"
.Replacement.Text = "Hello2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub CS1()
'
' CS1 Macro
' Macro recorded 7/17/2008
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading2")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub