• Removing space after footnote in notes

    Author
    Topic
    #507537

    I have some old code that doesn’t seem to work any more. Anyone have a better approach? I’m wondering if there’s I could use a range for that and how?

    Rem ******FINDING Space TO RIGHT OF NOTE NUM & DELETING******
    Rem Home
    Selection.GoTo What:=wdGoToFootnote, Which:=wdGoToFirst, Count:=1, Name:= _
    “”
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Find “^f “, 0
    BText “Removing the space after the note numbers”
    While Selection.Find.Found = True
    Rem GoRight 1
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
    SelectLeft 1
    If Selection.Range = ” ” Then Selection.Delete
    FindNext “^f “, 0
    Wend
    ActiveDocument.UndoClear

    Viewing 2 reply threads
    Author
    Replies
    • #1584215

      You seem to have lost a fair bit of code in translation. Try the following macro which takes a different look at the problem

      Code:
      Sub GoGo2()
        Dim aFN As Footnote, aRng As Range
        For Each aFN In ActiveDocument.Footnotes
          Set aRng = aFN.Range
          aRng.Collapse Direction:=wdCollapseStart
          aRng.MoveStart Unit:=wdCharacter, Count:=-1
          If aRng.Text = " " Then aRng.Text = ""
        Next aFN
      End Sub
      • #1584416

        Thanks Andrew! That worked perfectly.

        Do you have some suggestions on a source of information to brush up on using ranges in footnotes? I have a number of other, similar routines that remove tabs on either side of a footnote number, and remove a period after the footnote number I have yet to replace. This is one ugly macro that I’m working with. It originally started out in WordBasic. I’m trying to work every bit of old code out of it, as soon as I can.

    • #1584241

      From what you’ve posted, it appears you’re trying to delete spaces following the footnote references in the document body. For that you could use code like:

      Code:
      Sub Demo()
      Application.ScreenUpdating = False
      Dim FtNt As Footnote, Rng As Range
      For Each FtNt In ActiveDocument.Footnotes
        Set Rng = FtNt.Reference
        With Rng
          Do While .Characters.Last.Next = " "
            .End = .End + 1
          Loop
          .Start = .Footnotes(1).Reference.End
          .Text = vbNullString
        End With
      Next FtNt
      Application.ScreenUpdating = True
      End Sub

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    • #1584439

      I don’t have any suggestions for information sources other than simply asking the question here or on other forums. What you are trying to do is somewhat odd and unlikely to have been addressed in more structured information sources, books or online tutorials.

      I just record macros to get some keywords I can fiddle with or use to ask ‘Dr Google’ and then play with the vba intellisense to find most things if I haven’t read about it somewhere before. The more code you look at, the more you’ll learn about clever ways to performing tasks.

      As you can see from comparing Paul’s code with mine, Footnotes have a .Reference and a .Range. The .Reference property is where the number appears in your document body. The .Range property is where the actually footnote resides. Paul’s code included a loop to remove multiple spaces whilst mine only looked for one instance of a space. You should be able to adapt ideas from both these macros to extend your own macros.

    Viewing 2 reply threads
    Reply To: Removing space after footnote in notes

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: