#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
I find the Paste Special as Text Only workflow incredibly destructive. I usually like the content I paste to have useful things like tables, fields, footnotes, cross-references, graphics etc. Having to recreate these after doing a Text only paste is a waste of my time. There are alternatives that can achieve the intent without resorting to text only. This will allow you to retain your footnotes without having to recreate them.
For instance, if BEFORE you copy the text, apply Normal style (Ctrl+Shift+N) to the selection and remove local formatting with Ctrl+Q and Ctrl-Space. Then make your copy and paste normally. The worst that will happen is you might introduce some unused custom style names to your target document. You can run a simple loop to delete those quickly if they bother you. If you stick with the Text Only workflow, the footnotes themselves will remain an issue but you will also have to forensically hunt down all the footnote numbers scattered around in the text. You would need to put tags around all of these anchors before copying since they will convert to standard unformatted text after the paste as text only. I would experiment with converting to Endnotes in order to grab the footnotes in one easy way but realigning them with their original anchors is going to require lots of code.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Unfortunately, that recreation is part of the job for us. A large majority of the time we want the tables, fields, and cross-references removed. It is a safety net so that we know that if the document is still within the company there would be minimal change needed to be made to meet an immediate deadline.
Finding the footnotes themselves isn't too problematic once the code is run by going into Draft View and then Show Notes, but obviously being automated would be much easier. Thank you for the reply! |
#4
|
||||
|
||||
Following down the recreating path, perhaps this workflow will get you started. This uses an array to store the footnote entries as strings in an array and tag the locations. It then puts unformatted content into a new document and rebuilds the footnotes based on the tags inserted.
Code:
Private Sub NewDocPlusFootnotes() Dim arrFN() As String, aFN As Footnote, iFN As Integer Dim xDoc As Document, xNewDoc As Document, aRng As Range Set xDoc = ActiveDocument With xDoc 'Get the footnotes into a string array If xDoc.Footnotes.Count > 0 Then '.Footnotes.StartingNumber = 0 ReDim arrFN(1 To xDoc.Footnotes.Count) For Each aFN In .Footnotes aFN.Reference.InsertBefore "<fNote " aFN.Reference.InsertAfter "/>" arrFN(aFN.Index) = aFN.Range Next aFN End If End With 'Create new document and fill with plain text Set xNewDoc = Documents.Add xNewDoc.Range.Text = xDoc.Range.Text 'unformatted text into new doc 'rebuild the footnotes Set aRng = xNewDoc.Range With aRng.Find .ClearFormatting For iFN = LBound(arrFN) To UBound(arrFN) .Text = "<fNote " & Chr(2) & "/>" If .Execute = True Then aRng.Text = "" xNewDoc.Footnotes.Add Range:=aRng, Text:=arrFN(iFN) End If aRng.Collapse Direction:=wdCollapseEnd Next iFN End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Thank you for that, Guessed! I was able to get it to work with my code and have it paste unformatted text, my only question now is can I have the footnotes put in as unformatted text as well?
Thank you again! |
#6
|
||||
|
||||
The code I gave you is working as unformatted text. Are you saying you don't want them to be reconstructed as footnotes?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
When I run it, even on its own, it still seems to bring over unwanted characters, such as non-breaking spaces. It might just be a misconception on my part, but when I was referring "unformatted text," the idea I have in my mind would be the same as if you would copy text, Paste Special, and Paste Unformatted Text (which removes non-breaking spaces, etc. as well).
|
#8
|
||||
|
||||
That is interesting that pasting as text only converts non-breaking spaces to spaces. This is not something I've ever noticed before. Do you know of other character substitutions that happen with this?
To solve that issue, we can do a substitution either while loading the array or when placing the array contents. Let's do it while loading the array. Change this line arrFN(aFN.Index) = aFN.Range to arrFN(aFN.Index) = Replace(aFN.Range.Text, Chr(160), " ") 'replace non-breaking space with space
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#9
|
|||
|
|||
That I can think of off the top of my head: non-breaking hyphens turn into regular spaces and line breaks turn into regular returns.
While this does work for the non-breaking space problem, it isn't quite what I need, but it seems like it might be my best option if there isn't a Paste Special Unformatted Text option. As with the body of the document, our goal is to strip as much out as possible before we go in and basically recreate the formatting and look of the document with our own styles and numbering. But, either way, thank you again for you help, I've learned a good bit in trying to figure this out! |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Request for a macro to move footnotes (not formatted as footnotes) from end of page to end of doc | Pluckedchicken | Word VBA | 0 | 09-03-2020 05:21 AM |
How to change superscript footnotes into genuine Word footnotes | Knounte29 | Word VBA | 41 | 01-16-2020 04:48 PM |
creating manuscript w/footnotes from separate documents containing chapters with footnotes-word 2010 | Dottie | Publisher | 0 | 02-19-2017 03:18 PM |
Convert manual cross references in footnotes to other footnotes to automatic cross references | ghumdinger | Word VBA | 7 | 11-20-2014 11:47 PM |
Edit Data Source- Linking template charts to new data | lbf | PowerPoint | 0 | 10-28-2011 12:19 PM |