0
votes

I need help converting 1980s DOS word processor documents into Microsoft Word 2016 documents. The DOS word processor program, Final Word, formats text with in text special character combinations.

Word opens these documents. Text is read as text and the formatting characters are translated as extended Ascii characters as shown here:

Historical studies are still undertaken and judged with a very different logic than are sociological ones. Conversely, sociologists who study history have quite different methodological orientations than do historians.ÀÆÏÏÔûVictoria E. Bennett, "The Uses of Theory. Concepts and Comparison in Historical Sociology", ÀÉûComparative Studies in Society and History.ý, ÀÂû22ý, 1980.ý. Apart from a more conscious concern with quantification the kind of history that is being written today seems to be little different as far as the perspective of the historical social scientist is concerned from that which was being written fifty years ago.

Italicized text, for example, is enclosed between the extended Ascii character string ÀÉû and ý, while bolding uses the characters ÀÂû and ý. Footnotes begin with the extended Ascii character string ÀÆÏÏÔû and end with the character ý preceded by a period (.).

I have written the following VBA macro that converts the extended Ascii character string encased in-line footnotes into bottom of page Word footnotes:

Sub FinalWordFootnotes() ' ' FinalWordFootnotes Macro

Selection.Find.ClearFormatting

With Selection.Find
    .Text = "ÀÆÏÏÔû*.ý"  '<---In-line footnote enclosed in extended Ascii character stings
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
 
While Selection.Find.Execute
    
    ActiveDocument.Footnotes.Add Range:=Selection.Range, Text:=Selection.Text
           
Wend

End With

End Sub

(Note: the text being searched for is any text between the extended Ascii character strings ÀÆÏÏÔû and..ý such as: ÀÆÏÏÔûVictoria E. Bennett, "The Uses of Theory. Concepts and Comparison in Historical Sociology", ÀÉûComparative Studies in Society and History.ý, ÀÂû22ý, 1980.ý.)

Unfortunately, this macro leaves the Ascii encased footnotes in the text. The bottom of page footnotes it creates also include the extended Ascii character strings.

Accordingly I need to revise my macro so that it also:

  1. Creates the in-line footnotes the Word bottom of page footnotes without the extended Ascii characters strings.
  2. Once the in-line footnote has been created, delete the in-line/in-text footnote used to create it, including its extended Ascii characters.

While I programmed extensively in Excel VBA some twenty years ago, I’ve largely forgotten it, and I have never written Word VBA macros. I would, then, be grateful for any suggestions and advice as to how I might revise my macro in this regard.

Suggestions as to how I could automatically format my documents to bottom of page footnotes using Arabic numbers before running this macro would also be appreciated. Presently I am doing it by creating a footnote using the Word References – Insert Footnote menu before I run my macro.

My thanks in advance for all your help, advice and suggestions.

1
Cross-posted at: vbaexpress.com/forum/…. For cross-posting etiquette, please read: excelguru.ca/content.php?184macropod

1 Answers

0
votes

I feel your pain. This is actually quite a tricky task because of the way in which the original document uses 'ý' as the closure for any run of formatting/footnote. This means a wildcard search for the whole footnote can't be certain if the found 'ý' is the closure for the footnote or some other formatting. Consequently, I think you have to deal with doing the formatting parts before you cut and paste the formatted text into the footnote.

The code below should help you on your way. You are likely to have issues with the 'Footnote Text' style so you may need additional code to reduce the font size etc. I'll leave that as an exercise for the OP.

Option Explicit

Sub ttest()

    DoBold ActiveDocument
    DoItalic ActiveDocument
    DoFootnotes ActiveDocument
    
End Sub


Public Sub DoItalic(ByVal ipDoc As Word.Document)

    With ipDoc.StoryRanges(wdMainTextStory)
    
        With .Find
        
            .ClearFormatting
            .Text = "(ÀÉû)(*)(.)(ý)"  ' THis gives founf fields of \1,\2,\3,\4 (ÀÉû)(*)(.)(ý)
            .Forward = True
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
            
            .Replacement.ClearFormatting
            .Replacement.Font.Italic = True
            .Replacement.Text = "\2\3"
            .Wrap = wdFindContinue ' for a formatting change we can process every ocurrent automatically
            
            .Execute Replace:=wdReplaceAll
            
        End With
        
    End With

End Sub

Public Sub DoBold(ByVal ipDoc As Word.Document)

    With ipDoc.StoryRanges(wdMainTextStory)
    
        With .Find
        
            .ClearFormatting
            .Text = "(ÀÂû)(*)(ý)"
            .Forward = True
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
            
            .Replacement.ClearFormatting
            .Replacement.Font.Bold = True
            .Replacement.Text = "\2"
            .Wrap = wdFindContinue
            
            .Execute Replace:=wdReplaceAll
            
        End With
        
    End With

End Sub

Public Sub DoFootnotes(ByVal ipDoc As Word.Document)

    With ipDoc.StoryRanges(wdMainTextStory)
    
        With .Find
        
            .ClearFormatting
            .Text = "(ÀÆÏÏÔû)(*)(.)(ý)"  ' THis gives found fields of \1,\2,\3,\4 (ÀÉû)(*)(.)(ý)
            .Forward = True
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
            
            .Replacement.ClearFormatting
            .Replacement.Text = "\2\3"
            .Wrap = wdFindContinue ' for a formatting change we can process every ocurrent automatically
            
        End With
        
        ' The conditions for the find have been set up. No need to repeat the above
        ' do repeat single instance find until we have dealt with all instances
        
        Do While .Find.Execute(Replace:=wdReplaceOne)  ' the replace removes the extended asci

            ' Capture the formatted text
            .Cut
            
            ' Create a new footnote and paste formatted text
             .Footnotes.Add(Range:=.Duplicate).Range.PasteAndFormat wdFormatOriginalFormatting
            
       Loop
        
    End With
        
End Sub