PDA

View Full Version : [SOLVED:] Take footnotes from source and put into new template



rgsl111
10-26-2021, 12:19 PM
I've been working on piecing together a program thanks to a high school VBA class years ago and searching this site 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). Any help would be greatly appreciated!

Here is what is have so far:


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
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

Thank you!

Chas Kenyon
10-26-2021, 03:16 PM
Not a solution but a note about Word jargon. In Word jargon, "template" has a somewhat different meaning from usage in general English or even technical writing. Here is my page on templates: Templates in Microsoft Word (http://www.addbalance.com/usersguide/templates.htm). To maintain clarity, I would call what you are using a pattern document.
Also, command buttons (Active X) are being deprecated and do not work on the Mac versions at all. Perhaps you are using a UserForm rather than ActiveX.

gmayor
10-26-2021, 09:14 PM
It occurs to me that you could create a new document by using the document from which you are copying as a template (File > New). This would bring everything from that document. You can then format it as you wish.

rgsl111
10-27-2021, 05:04 AM
Based on a quick read through of your link, I still believe that it is a template. It is a .dotx file that is used to hold our modifications of Normal, margins, adding a number of custom styles, and a default listing for our numbering suite program. We use this (and other) "templates" when creating a new document instead of the blank document option so all fonts, sizes, points before and after, spacing, etc. all remain consistent. And yes, it is a UserForm, just a simple 3-button dialog box to execute different versions of this script (and Mac use is of no concern).

I suppose I should start with a background of the process that this is being used for. Without going into to 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.

I hope that can clarify what I am trying to accomplish with this. Again, any and all help is greatly appreciated and thank you for the responses so far!

Chas Kenyon
10-28-2021, 07:30 AM
Thank you for your response. Yes, you are using templates and using them well. I hope you are moving your text into new documents created based on your templates.