Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2014, 09:52 PM
TimFromPhx TimFromPhx is offline Macro to find text only footnote numbers Windows 7 32bit Macro to find text only footnote numbers Office 2007
Novice
Macro to find text only footnote numbers
 
Join Date: Apr 2014
Posts: 4
TimFromPhx is on a distinguished road
Default Macro to find text only footnote numbers


I convert ebooks into text so I can convert them with text to speech software so I can listen to them. I want to create a macro so I can search for footnote numbers in order. First I want to search for 1 then 2 then 3 so I can delete them. I would need to find a number and if it is the correct number I want to delete it, if not I need to search for the next occurrence of the same number and delete it if it is the correct one. If I delete the number then it should increment the number and search again.

These footnotes are just text numbers, they are not actual Microsoft Word footnotes. They also are not superscript or subscript.
Reply With Quote
  #2  
Old 04-10-2014, 02:34 AM
macropod's Avatar
macropod macropod is offline Macro to find text only footnote numbers Windows 7 32bit Macro to find text only footnote numbers Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If all you want is a means to Find numbers, you can use a wildcard Find for:
[0-9]{1,}
You don't need a macro for this; the only thing a macro might add to the process is the ability to not stop at a number that is lower than the last one found. However, given that a document can contain more than one reference to the same footnote, and the numbering therefore won't be sequential, that's not much use.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-10-2014, 02:58 AM
TimFromPhx TimFromPhx is offline Macro to find text only footnote numbers Windows 7 32bit Macro to find text only footnote numbers Office 2007
Novice
Macro to find text only footnote numbers
 
Join Date: Apr 2014
Posts: 4
TimFromPhx is on a distinguished road
Default A macro would make this process significantly faster.

I am an e-book addict. I have been taking e-books and turning them into clean text and then into audio for about 5-1/2 years now. I've listened to about 2500 nonfiction e-books. I use firebug to copy the innerHTML in the body copy and then strip out all of the HTML tags and I am then left with clean text except for the footnotes and some other problems that I need to clean up.

I have functions that I use to remove things that are in parentheses, square brackets, curly brackets and then I perform a whole series of text manipulations on the text to prepare it for the text to speech software to work properly.

Getting rid of the footnote numbers has been a major pain. Currently I go through the book from top to bottom and manually find each footnote number and delete it. Sometimes the numbering starts at one in the first chapter and can go up to 250 or more by the end of the book. Other times, the numbering restarts at 1 for each chapter.

I wrote a macro that started at the highest number footnote and searched backwards for each number as a negatively incremented counter. But the problem is when there are dates or other sorts of numbers within the text the deletion process deletes the wrong numbers.

I don't mind working my way through the document, looking at each individual footnote number but visually searching for the numbers is somewhat straining.

I thought perhaps there might be some way to create a modal window with yes or no buttons and a (reset counter to 1) button so I could hit the yes or no button to confirm the deletion of each number. If I had no it would search forward and find the next occurrence of the counter variable. If I hit yes it would delete the number from the page then increment the variable and search again. If I hit reset it would set the variable to 1 and start searching again.

This would really be extremely handy and I truly appreciate any help you might be able to give.

Tim Anderson
Reply With Quote
  #4  
Old 04-10-2014, 05:58 AM
macropod's Avatar
macropod macropod is offline Macro to find text only footnote numbers Windows 7 32bit Macro to find text only footnote numbers Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If the e-book material starts off with formatting such as superscripting for footnotes, it would be far easier to use Find/Replace (even in a macro) to delete them at that point - or even convert them to real footnotes (since, presumably, you have the footnote content that goes with them) - than to try to do it after the formatting has been removed. The same applies to processing any other formatted content.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-10-2014, 09:29 AM
TimFromPhx TimFromPhx is offline Macro to find text only footnote numbers Windows 7 32bit Macro to find text only footnote numbers Office 2007
Novice
Macro to find text only footnote numbers
 
Join Date: Apr 2014
Posts: 4
TimFromPhx is on a distinguished road
Default The footnotes in the original text is in normal text format

The footnotes are regular text without any formatting whatsoever even in the original text.

In my previous note I was assuming that the macro would use find and replace to do the text deletion.

I guess all I would really need to see is a window that finds text then deletes the text if I i hit one button or searches again if I don't want to delete it. Sort of like find and replace buttons on the search and replace window.

I can write the code for incrementing the counter.
Reply With Quote
  #6  
Old 04-10-2014, 03:20 PM
macropod's Avatar
macropod macropod is offline Macro to find text only footnote numbers Windows 7 32bit Macro to find text only footnote numbers Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use a macro like:
Code:
Sub Demo()
Dim Rslt, Rng As Range
Set Rng = Selection.Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "[0-9]{1,}"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    If (.Characters.First.Previous <> "/") And (.Characters.Last.Next <> "/") Then
      .Select
      Rslt = MsgBox("Replace this instance of:" & vbCr & .Text, vbYesNoCancel)
      If Rslt = vbCancel Then Exit Sub
      If Rslt = vbYes Then .Text = vbNullString
    End If
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Rng.Select
End Sub
Do note that the message box the code uses is liable to hide the found text at times; you can drag the box out of the way, though. Given that, as I said before, footnote numbers won't always be sequential, I don't see what the counter would achieve.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-10-2014, 05:40 PM
TimFromPhx TimFromPhx is offline Macro to find text only footnote numbers Windows 7 32bit Macro to find text only footnote numbers Office 2007
Novice
Macro to find text only footnote numbers
 
Join Date: Apr 2014
Posts: 4
TimFromPhx is on a distinguished road
Default Is there a quicker way to search?

I created a form with the following code:
It works okay, but the process is too slow because I get too many false matches.
Code:
Public FootnoteCounter As Integer 
Private Sub CurrentFootnote_Change() 
    FootnoteCounter = Me.CurrentFootnote.Value 
End Sub
 
Public Sub FindFootnote_Click() 
    Selection.Find.ClearFormatting 
    With Selection.Find 
        .Text = FootnoteCounter 
        .Replacement.Text = "" 
        .Forward = True 
        .Wrap = wdFindContinue 
        .Format = False 
        .MatchCase = False 
        .MatchWholeWord = False 
        .MatchWildcards = False 
        .MatchSoundsLike = False 
        .MatchAllWordForms = False 
    End With 
    Selection.Find.Execute 
End Sub
 
Public Sub DeleteFootnote_Click() 
    Selection.Delete 
    Selection.Find.ClearFormatting 
    With Selection.Find 
        .Text = FootnoteCounter 
        .Replacement.Text = "" 
        .Forward = True 
        .Wrap = wdFindContinue 
        .Format = False 
        .MatchCase = False 
        .MatchWholeWord = False 
        .MatchWildcards = False 
        .MatchSoundsLike = False 
        .MatchAllWordForms = False 
    End With 
    Selection.Find.Execute 
End Sub 
 
Public Sub IncrementCounter_Click() 
    FootnoteCounter = FootnoteCounter - 1 
    Me.CurrentFootnote.Value = FootnoteCounter 
    Selection.HomeKey Unit:=wdStory 
End Sub
My code does one of the following functions: Find a match, Delete selection and find next match, Increment the counter.

I'm starting with the highest footnote number and working through backwards because it is quicker. For instance searching for "1" returns 1, 11, 141, 1990, etc. I get less errors if I search in reverse.

Can you think of a way to do a search for "1" that would not find 11, 141, 1990, etc?

Is there a way I could use a regular expression to do the search that would exclude numerals to the left or right of my target?

Thanks for all your help

Last edited by macropod; 04-10-2014 at 06:51 PM. Reason: Added code tags & formatting
Reply With Quote
  #8  
Old 04-10-2014, 07:05 PM
macropod's Avatar
macropod macropod is offline Macro to find text only footnote numbers Windows 7 32bit Macro to find text only footnote numbers Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If you only want to find numbers that increment try:
Code:
Sub Demo()
Dim Rslt, Rng As Range, i As Long
Set Rng = Selection.Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "[0-9]{1,}"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    If .Text = i + 1 Then
      .Select
      Rslt = MsgBox("Replace this instance of:" & vbCr & .Text, vbYesNoCancel)
      If Rslt = vbCancel Then Exit Sub
      If Rslt = vbYes Then
        .Text = vbNullString
        i = i + 1
      End If
    ElseIf .Text = i Then
      .Select
      Rslt = MsgBox("Replace this instance of:" & vbCr & .Text, vbYesNoCancel)
      If Rslt = vbCancel Then Exit Sub
      If Rslt = vbYes Then .Text = vbNullString
    End If
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Rng.Select
End Sub
Note: As coded, the macro includes an ElseIf test to pick up repeats of the last number. You can delete that if you don't want it.

I'm not sure what you mean by "Is there a way I could use a regular expression to do the search that would exclude numerals to the left or right of my target?" The code in both this post and my previous one (both of which use wildcards, which are Word's equivalent of regular expressions) only picks up whole numbers anyway - it won't find just the 1 or 11 within 110 or 211 or 123114, for example.

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to find text only footnote numbers Macro to find text and replace with form field containing that text iiiiifffff Word VBA 16 06-04-2016 01:47 AM
Macro to find text in between two characters and then format selected text? qcom Word 5 02-19-2015 11:23 PM
Macro to find text only footnote numbers VBA code for Microsoft Word macro — select text and insert footnote ndnd Word VBA 10 01-06-2015 01:47 PM
Macro to find text only footnote numbers Need help on Macro 03- Find text - if text is blank then remove line simpleonline1234 Word VBA 1 02-25-2011 02:28 AM
Find and replace page numbers in body of text tollanarama Word 3 02-13-2011 06:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft