word 2003 vba

friedpiggy

Expert Member
Joined
Aug 6, 2005
Messages
1,709
Reaction score
1,273
Location
127.0.0.1
Hoping someone can help.

Trying to do a find on a style. Using selection as it just needs to find the paragraph with that style for use by a couple of other functions.

Code works 100% in word xp and lower. In 2003 however it just bombs.

heres what Im using

Sub Macro1()

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("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

if i run that it finds zero results. If I then go back into word and have a look at what its doing, the find dialogue box has a whole load of other weird stuff in it. So I record a macro with the new stuff and the code looks like so.

Sub Macro2()

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("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

Now it may just be me, but where the **** did the additional 20+ lines of border stuff come from?

If anyone has a clue it would be greatly appreciated.
 
Yes - It is just you

You have set the border in the 2003 version IE SEcond Macro.

With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With

Shows for example that the right border of the selected cell has a border set.
 
ow the joys of vb.... had to do some fun vb stuff for excel sheets the past month :D
 
Yes - It is just you

You have set the border in the 2003 version IE SEcond Macro.

um nope. The second macro is what is generated when the first macro is run.

open word and run the first macro and it finds nothing, if you then look at the find dialogue under the input box it lists the style plus some other things, record that and all the border stuff is there. so in other words, running the first macro inserts all the border stuff into the find as well.

so it isnt just me.

On a more positive note however, I managed to find a workaraound for it. so my problem is solved. only took 12 hours of hunting the web to find it hidden away on some russian site.
 
Top
Sign up to the MyBroadband newsletter
X