Consulting

Results 1 to 4 of 4

Thread: Solved: I want to replace only in footnotes that are in selection

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location

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

    this one goes also thrugh footnotes that are not in selection any ideas why
    [vba]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
    [/vba]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    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:
    [VBA]
    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
    [/VBA]

    HTH
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #3
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    Thnx man I really appreciate this, it works like a charm

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Saban,

    Quote Originally Posted by saban
    Thnx man I really appreciate this, it works like a charm
    You're most welcome!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •