PDA

View Full Version : Convert text in footnotes



Pasquale
08-25-2006, 12:21 PM
Hallo I need help.
I have a long doc where footnotes are for a mistake formatted .
The doc file is formatted in txt losting footnotes.

Example:
The text is:
3. ?And he shall be like [10] a tree planted hard [11] by the running streams of [12] which vouchsafed to Psalm, ?the river of God is full of water.? [13] Or by the Holy Ghost, of whom it is said, ?He shall baptize you in the Holy Ghost;? [14] and again, ?If any man thirst, let him come unto Me, and drink;? [15] and again, ?If thou knewest the gift of God, and who it is that[16]

and relative footnotes now formatted in txt

[10] John viii. 5, 6.

[11] Ps. xvi. 7.

[12] Prov. viii.

[13] Ps. lxv. 9.

[14] Matt. iii. 11.

[15] John vii. 37.

[16] John iv. 10, 14.

I must create footnotes with [12] and [12], [13] and 13 and so on.

Thanks Pasquale

EricFletcher
08-28-2006, 05:55 PM
Can you clarify what you want? Did the entire document get saved as text with the footnotes included as your sample? I.e., does your document have both the footnote reference numbers (like [10]) and the footnote content (as "[10] John viii. 5, 6."?

If it does, you could use a VBA routine to use the selected footnote content to find its footnote reference in the body and create the linked footnote. But please clarify first...

Pasquale
08-28-2006, 08:59 PM
Hallo, EricFletcher,
you have understand very well the problem.
1) the entire document get saved as text with the footnotes included.
2) The document have both the footnote reference numbers (like [10]) and the footnote content (as "[10] John viii. 5, 6."?).
3) I need a VBA routine to use the selected footnote content to find its footnote reference in the body and create the linked footnote.

thanks for help
Pasquale

EricFletcher
09-04-2006, 05:18 AM
Here?s how I would approach the problem Pasquale. It works directly from Word using copy/paste instead of the variables -- but I?ll let someone more adept at VBA help put suitable code around it!

1. Use Find what with wildcards to find the pattern ?(\[)([0-9]{1,2})(\])? and if found, set the selection as a variable, say thisFnNum. (The wildcard search finds the pattern with [ + any 1 or 2 digits + ].)

2. Set a bookmark to flag the location (thisFnLocation).

3. Find (without Wildcards) using Find what=thisFnNum.

4. If found, delete the selection (to get rid of the hard-wired footnote # + the space if one follows it), then select the paragraph (which will contain the footnote content) and set it as thisFnContent.

5. Remove the last character (the ?) from thisFnContent.

6. Go back to the thisFnLocation bookmark and delete it to remove the hard-wired footnote number. (Note that you may need to remove the space before or after it too: the sample text has the ?[10]? surrounded by spaces so it isn?t clear how you will want it to look after the Word footnotes are inserted.)

7. Insert | Reference, Footnote and use thisFnContent as the text for the footnote.

Now you have the first footnote set. To set all of them, loop through steps 1-7 until step #1 doesn?t find anything. If you are unsure about how to make this into VBA, post again, but try recording the above to get the basics first.

Pasquale
09-04-2006, 06:00 AM
Hallo Eric,
Thank you for Help.

J am not be able to set the first bookmark, I try but is hard.

Thanks

pasquale

EricFletcher
09-04-2006, 06:23 AM
I assume you were able to find the footnote using the wildcard expression in Find. Great! This will have found your footnote call in the text -- where you will want the true Word footnote call -- but you'll need to be able to now find the related textual footnote and then jump back to this location.

The bookmark "marks" the location while you look for the associated text for it. To set a bookmark to the selection, use the Insert | Bookmark dialog and type a bookmark name (I used "thisFnLocation" but you can use whatever makes sense for you).

Now you have a location to be able to jump back to after you find the related footnote paragraph. You can test it outside of VB by pressing F5: select Bookmarks in the dialog and select your bookmark name from the list on the right. When you click OK, it will jump back to the footnote location.

I suggest you go through the whole procedure manually first to make sure you have it right, then record it. You can either play back the recording for each footnote if there are only a relatively small number to process, or modify the recorded code to add a loop structure to process all of the footnotes.

Pasquale
09-04-2006, 06:50 AM
Hi Eric, i set first bookmark (first=testo; second: nota); Must I assign a name at all reference?

Exscuse me

pasquale

EricFletcher
09-04-2006, 07:03 AM
I'm not sure I follow your question. Here's a quick & dirty modified recording that you can play with. It works for the sample content you provided initially but you may need to modify things to suit your documents.

Sub FootnotePlacer()
'
' For Pasquale on VBAX forum
' Macro recorded 04/09/2006 by Eric Fletcher

Dim thisFnLocation, thisFnNum, thisFnContent As String

'-- Start at the top and ensure you are in Normal view
Selection.HomeKey Unit:=wdStory

'--Find the first footnote pattern
Selection.Find.ClearFormatting
With Selection.Find
.Text = "(\[)([0-9]{1,2})(\])"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute

thisFnNum = Selection '-- this holds the pattern found

With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="thisFnLocation"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1

Selection.Find.ClearFormatting
With Selection.Find
.Text = thisFnNum '-- use the found pattern to find the footnote in text
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

'-- The selection now has the footnote number but you want the content only
' so delete the number and isolate just the text (i.e. not the paragraph mark)
' and delete it from here
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
thisFnContent = Mid(Selection, Len(thisFnNum) + 2, Len(Selection) - 3)
thisFnContent = Trim(thisFnContent)
Selection.Cut

'-- Now go back to where the footnote was called and add the footnote
Selection.GoTo What:=wdGoToBookmark, Name:="thisFnLocation"
Selection.Delete Unit:=wdCharacter, Count:=1
' Selection.Collapse Direction:=wdCollapseStart
ActiveDocument.Footnotes.Add Range:=Selection.Range, Text:=thisFnContent

End Sub

Pasquale
09-04-2006, 07:15 AM
Thank sEric I am trying:

Pasquale