PDA

View Full Version : Find and Replace macro causes borders to appear



slf221
07-07-2006, 09:28 AM
Hi,

I'm working in Word 2003, doing a find and replace to change all tabs to indents. Every time I run the macro, all modified paragraphs end up with borders and the border specifications appear in the replace dialog box. Any idea why this is or how to fix it? Here's my macro:

test2 Macro

' Macro recorded 7/6/2006 by MCSD
'
ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
ShowAll
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceDouble
.Alignment = wdAlignParagraphLeft
.FirstLineIndent = InchesToPoints(0.5)
.CharacterUnitFirstLineIndent = 0
End With
Selection.Find.Replacement.ParagraphFormat.TabStops.ClearAll
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = "^t"
.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
Selection.HomeKey Unit:=wdStory
End Sub



Any help would be GREATLY appreciated!!

lucas
07-07-2006, 10:09 AM
Your going to have to upload an example as I can't duplicate your problem

slf221
07-07-2006, 10:15 AM
Okay - I MAY have fixed the borders issue, but I can't seem to get the tabs to be completely removed -- it is just adding an indent where a tab already exists. And how do I get it to go back to being flush left after the next hard return?

Thanks from a VBA newbie!

mdmackillop
07-09-2006, 06:53 AM
I don't understand the border issue.
Regarding the tabs, it needs to be done twice, (from my attempts)
try

Sub TabToIndent()
With ActiveDocument.Content.Find
.Text = "^t"
.Replacement.ParagraphFormat.FirstLineIndent = _
InchesToPoints(0.5)
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Text = "^t"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End Sub