HenryAte
11-25-2008, 10:08 AM
Hi There.
Seriously hoping someone can help with this one.
I need to find an occurrence of a specific style, The problem is that word seems to be adding in some weird stuff.
Using word 2003 on Win XP Pro.
Steps followed.
1) open doc
2) record a macro to find a style
3) style is found, end recording.
4) run macro - no results found.
5) go back into word and record a second macro
6) open find dialogue and click find next to see what happens, no results found.
7) stop recording and look at code of second macro
8) more than 20 lines of paragraphformat stuff added to find function.
Here is the code from the first recording
Sub Macro1()
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("LG-section")
Selection.Find.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
End Sub
then the second recorded macro comes out like so
Sub Macro2()
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("LG-section")
With Selection.Find.ParagraphFormat
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders
.DistanceFromTop = 0
.DistanceFromLeft = 0
.DistanceFromBottom = 0
.DistanceFromRight = 0
.Shadow = False
End With
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
Does anyone have any suggestions on how I can get it to find a style?
Many thanks indeed
Seriously hoping someone can help with this one.
I need to find an occurrence of a specific style, The problem is that word seems to be adding in some weird stuff.
Using word 2003 on Win XP Pro.
Steps followed.
1) open doc
2) record a macro to find a style
3) style is found, end recording.
4) run macro - no results found.
5) go back into word and record a second macro
6) open find dialogue and click find next to see what happens, no results found.
7) stop recording and look at code of second macro
8) more than 20 lines of paragraphformat stuff added to find function.
Here is the code from the first recording
Sub Macro1()
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("LG-section")
Selection.Find.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
End Sub
then the second recorded macro comes out like so
Sub Macro2()
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("LG-section")
With Selection.Find.ParagraphFormat
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders
.DistanceFromTop = 0
.DistanceFromLeft = 0
.DistanceFromBottom = 0
.DistanceFromRight = 0
.Shadow = False
End With
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
Does anyone have any suggestions on how I can get it to find a style?
Many thanks indeed