View Single Post
 
Old 10-27-2021, 11:37 AM
rgsl111 rgsl111 is offline Windows 10 Office 2016
Novice
 
Join Date: Oct 2021
Posts: 5
rgsl111 is on a distinguished road
Default Take footnotes from source and put into new template

I've been working on piecing together a program thanks to a high school VBA class many years ago and searching through websites that, among other things, takes an "outside" document, pastes it as unformatted text into a blank template, and runs through a number of mostly find/replace functions. Problem is that it doesn't bring over footnotes. I was able to get it to insert the in-paragraph footnote marks and currently have it pasting the content of the footnotes at the end of the document to be manually placed, but I'm trying to be able to get it to insert the content into its corresponding footnote, but it is a good bit above my ability (and a good bit of this is probably fairly inefficient, but I don't get any errors, so I don't question it).

I suppose I should start with a background of the process that this is being used for. Without going into too much detail, I work in a Word Processing department where we take agreements, letters, court documents, etc. that we receive from outside sources and "format" the documents using our own in-house styles and numbering suite (Innova). Directly formatting the documents we receive have caused many problems in the past where functions of the numbering suite, table of contents, and revising don't work as they normally should, so we have made it our standard procedure to copy and paste special as unformatted text into our "templates" most of the documents we receive and then apply our styles and numbering to this "fresh" document. Originally, the main purpose of this program was simply to use find/replace and insert non-breaking spaces and hyphens. It eventually snowballed into something that would do the entire copy/paste process for us, retaining bold, italics, underline, and highlighting using find/replace, as well as inserting the non-breaking characters and other department specific actions. Since we adopted this copy/paste standard, there was always the problem of footnotes not being brought over, thus that was the next thing on the list to be added to the ever-growing script.

Here is what is have so far:

Code:
Private Sub CommandButton1_Click()

With ActiveDocument

.AutoHyphenation = False

With .Range
With .Find

Dim xRange As Range
Set xDoc = ActiveDocument
If xDoc.Footnotes.Count > 0 Then
Set xRange = xDoc.Footnotes(1).Range
xRange.WholeStory
xRange.Select

ActiveDocument.Paragraphs.Add
ActiveDocument.Content.InsertAfter "Footnotes"
ActiveDocument.Paragraphs.Add

Selection.Copy
Set Range2 = ActiveDocument.Content
Range2.Collapse Direction:=wdCollapseEnd

Range2.Paste

.Text = "^f"
.Replacement.Text = "<footnote>"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.MatchWildcards = True
.Wrap = wdFindContinue
.Font.Underline = True

End If
End With
End With

Dim wholeDoc As Document
Dim wholeRange As Range
Set wholeDoc = ActiveDocument
Set wholeRange = wholeDoc.Range(Start:=0, End:=0)
wholeRange.WholeStory
wholeRange.Select
Selection.Copy
Set Range3 = ActiveDocument.Content
Range3.Collapse Direction:=wdCollapseEnd
Application.ScreenUpdating = False
Application.ScreenUpdating = True

.Text = ""
.Replacement.Text = "<u>^&</u>"
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Highlight = True
.Replacement.Text = "<h>^&</h>"
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Font.Bold = True
.Replacement.Text = "<b>^&</b>"
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Font.Italic = True
.Replacement.Text = "<i>^&</i>"
.Execute Replace:=wdReplaceAll

End With

Documents.Add ("12pt Template")

With ActiveDocument
Set myRange = Selection.Range
myRange.WholeStory
Selection.PasteSpecial DataType:=wdPasteText

EmphasisFormatClean

WPDFormat

End With
Unload Me

End Sub
Any help is greatly appreciated! Thank you!
Reply With Quote