PDA

View Full Version : Solved: I want to replace only in footnotes that are in selection



saban
06-21-2008, 02:07 PM
this one goes also thrugh footnotes that are not in selection any ideas why
Dim objFtn As Footnote
'Selection.HomeKey wdStory
Dim rngFoot As Footnote
Dim rngTmp As Range
Dim sel As Selection
Set sel = Selection
For Each rngFoot In sel.Footnotes
Set rngTmp = rngFoot.Range
With rngTmp.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^w" ' .Text = " [ ]@([! ])"
.Replacement.Text = " " '.Replacement.Text = " \1"
' .MatchWildcards = True
.Wrap = wdFindStop
.Format = False
.Forward = True
.Execute Replace:=wdReplaceAll
End With
Next rngFoot

MOS MASTER
06-22-2008, 02:24 PM
Hi Saban,

This is one of those things that we can't explain and why MS Word is different. (some of us like it's quirks and some don't) ;)

In this case the For each construction will still return all available all footnotes available in the document. (I've seen this behaviour more)

Therefore you'd better use a For Next loop and itterate the footnotes by index.

So I think you need something like this to find & replace only in the footnotes that are present in the current selection:

Option Explicit
Sub CheckFootNotes()
Dim iCnt As Integer
With Selection
For iCnt = 1 To .Footnotes.Count
With .Footnotes(iCnt).Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = " [ ]@([! ])"
.Replacement.Text = " \1"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
.Execute Replace:=wdReplaceAll
End With
Next
End With
End Sub


HTH

saban
06-22-2008, 04:18 PM
Thnx man I really appreciate this, it works like a charm:thumb

MOS MASTER
06-23-2008, 09:43 AM
Hi Saban, :hi:


Thnx man I really appreciate this, it works like a charm:thumb

You're most welcome!