Link to home
Create AccountLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Create a Book with chapters from Multiple documents

I am a pastor ... and every sermon I ever did is saved in a MS Word.document

I teach in "Series"

I would like to create a "Book" for each "Series"

Is there a way to pull in each MS Word Document as it's own chapter?
Avatar of Robert
Robert
Flag of United States of America image

My suggestion would be to convert them into an ebook.

You may need to do a few steps to convert it but there are several guides and tools out there that can help you through the process.
Editing e-books — calibre 5.19.0 documentation (calibre-ebook.com) 

If you wanted to keep in in word though the process would be a matter of combining them into a single document then creating a table of contents to link to the specific sections.
Insert a table of contents - Office Support (microsoft.com) 

ASKER CERTIFIED SOLUTION
Avatar of John Korchok
John Korchok
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
As an alternative to John's "Master document" approach, you could assemble them all into a single document using the IncludeText field code. Since you have many documents, it would probably make sense to insert one as an example, then "build" the assembled document by editing copies of it with the field codes revealed (Alt-F9).

The IncludeText field code pulls in the content of the named file without affecting the original document, and can avoid many of the complications that can arise with Word's master document feature. 

If you use the Master Document as a temporary file, there are no "complications". To reduce the temptation to keep the master, here's my handy macro to create a master document from a folder full of Word files:
Sub AssembleBook()
    Dim SubDocFile$, FolderPath$, Template$
    Dim Counter&
    Dim oFolder As FileDialog
    Dim oBookmark As Bookmark
    Dim oTOC As TableOfContents

'Create a dynamic array variable, and then declare its initial size
    Dim DirectoryListArray() As String
    ReDim DirectoryListArray(1000)

'Use the built-in Folder Picker dialog to choose the folder holding all the subdocuments
    Set oFolder = Application.FileDialog(msoFileDialogFolderPicker)
    With oFolder
        .AllowMultiSelect = False
        If .Show <> 0 Then
            FolderPath$ = .SelectedItems(1)
        Else
            GoTo EndSub 'If you cancel out of the dialog, this will exit the macro
        End If
    End With
    
'Turn off display updating for a less distracting appearance
    Application.ScreenUpdating = False
    
'Loop through all the files in the directory by using Dir$ function
    SubDocFile$ = Dir$(FolderPath$ & Application.PathSeparator & "*.*")
    Do While SubDocFile$ <> ""
        DirectoryListArray(Counter) = SubDocFile$
        SubDocFile$ = Dir$
        Counter& = Counter& + 1
    Loop

'Reset the size of the array without losing its values by using Redim Preserve
    ReDim Preserve DirectoryListArray(Counter& - 1)

'The following will sort the subdocuments by their name. You can prepend the name with a number to create any order you want them to be in the master document.
    WordBasic.SortArray DirectoryListArray()
    
'Start the master document process
    ActiveWindow.ActivePane.View.Type = wdOutlineView
    ActiveWindow.View = wdMasterView
    Selection.EndKey Unit:=wdStory
    For x = 0 To (Counter& - 1)
        If IsNumeric(Left(DirectoryListArray(x), 1)) Then
            FullName$ = FolderPath$ & Application.PathSeparator & DirectoryListArray(x)
            Documents.Open FileName:=FullName$, ConfirmConversions:=False
            With Documents(FullName$)
                .AttachedTemplate = Template$
                For Each oBookmark In Documents(FullName$).Bookmarks
                    oBookmark.Delete
                Next oBookmark
                .Close SaveChanges:=True
            End With
            Selection.Range.Subdocuments.AddFromFile Name:=FullName$, ConfirmConversions:=False
        End If
    Next x

'Optional TOC update for a master document that already has a table of contents
'    For Each oTOC In ActiveDocument.TablesOfContents
'        oTOC.Update
'    Next oTOC
    
'Switch back to Print Layout view and turn screen updating back on.
    ActiveWindow.ActivePane.View.Type = wdPrintView
    Application.ScreenUpdating = True
EndSub:
End Sub

Open in new window

Outside of Microsoft Word, there are also third-party book and formatting tools\ authoring programs you could do trials of online. I have been recently looking at Reedsy, but there are others especially if you want to publish or distribute it further. You still might have to do some tweaking, but automation may help:
Good strategy from @John Korchuk — and refreshing to see someone still using a WordBasic function in VBA!

One point that the OP should note is that the code will only process documents in the folder that begin with a number (i.e. IsNumeric(Left(DirectoryListArray(x), 1)) will not be true if a filename begins with a non-numeric character).

Re my mention of master document "complications"...
  1. While changes can be made to a sub-document after it is part of the assembled master, the procedure is fussy and it is easy to cause unintended changes. (Certainly for older versions of Word, making the edits in the sub-document was recommended.)
  2. If sub-documents have different templates attached, the appearance of same-named styles within them may change to reflect the style definition of the master document's version of the style. When you run John's code, a warning message will be displayed when this is detected. Note too that paragraph numbering may need to be checked and "restart" may be needed in a following sub-doc.
  3. Similarly, small differences in page setup dimensions can be very hard to detect, and can cause problems with section-related features. If the sub-docs are consistent, this won't usually be a problem, but becomes much more problematic if they come from multiple users with slightly different underlying templates. (And a nightmare if they are based on the default Normal template!)
The most frustrating problems I used to have with master documents came from #3 due to getting content from multiple sources & authors for assembling into collections of research papers. Chapters that had been "tweaked" for the author's specific printer setup would often have slightly different page layouts and frequently, different settings for page numbering, endnote/footnote and header/footers.

For @Larry Brister, assembling your book from a collection of your own documents is less likely to have some of those types of challenges — but you may find that your own Word habits have changed over time to let differences creep in.

When I need to create a full book from individual chapter files, I typically remove all sections (use F&R to change section breaks (^b) to a unique pattern to be able to reinsert later), then set the required dimensions and common section attributes for the entire book (header/footers for first, odd & even pages; numbering style; breaks, etc.). Then I can use Find to jump to each old section break location and replace the unique pattern with the appropriate type of section break. If they are all the same, I can copy the 1st one and use F&R to replace all of the others with the "find what" (^&) token.

For style differences (my #2 above), just be aware of the possibility, and make sure that the template you use for the book is the most up-to-date version of the template. If you are using styles, my recommendation is to turn off the "Automatically update" option of ALL styles to avoid unintentionally redefining a style by making a simple direct formatting change. (i.e. If you were to reduce the "space after" for a paragraph to avoid having content spill to an extra page in a chapter, every instance of that style in your book would instantly take on the change if this setting is turned on.)
Avatar of Larry Brister

ASKER

Eric... great advice and follow-up. Thanks!