Word - Macro to convert text to footnote based on conditions

M

Mongoose

Help. I'm really struggling with this but I can't seem to figure out
where it's going wrong. I'm still a beginner. I'm trying to write a
macro that runs through my document selecting text based on certain
conditions and then moving it to a footnote from that location. In
this case it is finding a word or phrase and moving the translation of
that word/phrase that follows between the |pipes| to the a footnote of
the word/phrase that has preceded it.

This is an example of the text I'm running it on everything in the
pipes (all formatted Font.Color = wdColorDarkBlue) is actually making
a footnote. But somewhere in the mix the footnotes are getting lost.

EXAMPLE TEXT

Human rights |amalungelo omutu wonke| include civil and political
rights, such as the right to life and liberty |inkululeko|.

MY MACRO


Sub Convert_to_footnote()
'
' Convert_to_footnote Macro
'
'
Dim oRange As Range
Dim fn As Footnote

Set oRange = ActiveDocument.Range
With oRange.Find
..ClearFormatting
..Forward = True
..Format = True
..Wrap = wdFindStop
..Font.Superscript = False
..Font.Color = wdColorDarkBlue
..Text = "|*|"
..MatchWildcards = True
..MatchDiacritics = True
..Execute

While .Found
Set fn = ActiveDocument.Footnotes.Add(oRange)

oRange.Move wdWord, 1
..Execute
Wend
End With
MsgBox ActiveDocument.Footnotes.Count
End Sub
 
D

Doug Robbins - Word MVP

Use the following code:

Dim fntext As String
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="|*|", Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=False) = True
fntext = Selection.Range.Text
fntext = Mid(fntext, 2, Len(fntext) - 2)
Selection.Text = ""
ActiveDocument.Footnotes.Add Range:=Selection.Range, Text:=fntext
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top