Consulting

Results 1 to 5 of 5

Thread: Take footnotes from source and put into new template

  1. #1
    VBAX Newbie
    Joined
    Oct 2021
    Posts
    2
    Location

    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 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!
    Last edited by Aussiebear; 10-28-2021 at 05:58 PM. Reason: Added code tags to supplied code

  2. #2
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    119
    Location
    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. 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.

  3. #3
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    VBAX Newbie
    Joined
    Oct 2021
    Posts
    2
    Location
    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!

  5. #5
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    119
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •