Step 1: NNELS Template for Word

Let's make some books.

Re: Step 1: NNELS Template for Word

Post by
rmarion
»
Sun Feb 18, 2018 4:20 pm
Thanks for posting this really useful macro. Does this assume that you have already added the NNELS style sheets to your templates folder?
rmarion
Posts: 62
Joined: Fri Feb 02, 2018 1:08 pm
Contact:

Re: Step 1: NNELS Template for Word

Post by
Daniella.LP
»
Sun Feb 18, 2018 5:15 pm
Hi,

Yes. The macro assumes that the NNELS template is located in the same folder as the normal.dotx (more accurately, in the location of the template of the active document). This can be modified by changing the value of the variable "strTemplate" where you can define any adhoc location.
Daniella.LP
Posts: 77
Joined: Sat Feb 03, 2018 6:20 am
Contact:

Re: Step 1: NNELS Template for Word

Post by
farrah
»
Thu Feb 22, 2018 4:36 pm
Wow, thanks Daniella! I'm going to attempt to get this working on my end. I use Word for Mac...
Daniellalpl wrote:
Sun Feb 18, 2018 1:18 pm
I asked my husband for help to create a macro to delete the styles in the document and replace them with those in the NNELS template at once. He refined the code that Steve referred to and developed a macro that is working very well for me. The code is pasted below. I have also put the .bas file in the NNELS Production shared Dropbox folder.

Instructions to import and use the macro (I am using Word 2016).

1. With Word open, press Alt+F11 to open Microsoft Visual Basic for applications.
2. Within VBA, press Alt+F and find the "Import file" option or press Control+M.
3. In the dialogue box, you can browse your folders to Find and select the .bas file, in this case "ModuleChangeStyle.bas" and click "Open".
4. Close Visual Basic with Alt+F4.
5. From Word, Press Alt+w, M, V to view the list of available macros, press Down Arrow to find the "Replace styles", and click the "Run" button.

I tested this macro in Hit the Ground Running, as well as in the book I selected for the project and it works like magic indeed!

Note: make sure that no image is selected in the file before running the macro; if an image is selected, the macro will not work.

***Code begins below***

Sub ReplaceStyles()
'
' Replace styles
'
'
' Removes user-defined templates
For Each sty In ActiveDocument.Styles
If sty.BuiltIn = False Then sty.Delete
Next

' Updates template, assumes same location as normal.dotx
Set myTemplate = ActiveDocument.AttachedTemplate
strTemplate = myTemplate.Path & Application.PathSeparator & "nnels_styles.dotx"
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = strTemplate
End With
End Sub
farrah
Posts: 41
Joined: Tue Feb 06, 2018 10:50 am
Contact:

Re: Using Pandoc to produce .docx with NNELS style

Post by
farrah
»
Thu Feb 22, 2018 4:45 pm
Hi Daniella. This is super useful. I noticed that it did a perfect job of clearing all formatting so that just the Normal style was left. This is a great first step. It didn't apply the NNELS styles to the new document though, i.e. headings, blockquote, etc.
Daniellalpl wrote:
Thu Feb 15, 2018 4:06 pm
I used Pandoc in order to replace the style of the document with the NNELS style. The process can be done in one step, directly from the .epub file, but I started from the .docx file that we all received by email from Sabina.

I have used Pandoc quite a bit to produce many Word documents, including some with specific styles, directly from a text file that I create using Markdown (which uses punctuation symbols to indicate text attributes). In my experience, Pandoc is a more reliable tool than Word itself, in terms of generating documents that are consistently formatted: I know that the style I want will be applied to the resulting file, and I don't have to worry about Word making assumptions about the format if I move something without noticing. Some editing of the resulting .docx file may be necessary, but I find the process much simpler than trying to apply a complex format to a document in Word by hand.

I try to use short file names to make the code simpler, but you can have longer file names; however, it is important to ensure that the file names do not have any spaces (I use underscores, or capital letters to name the files). Also, I always work from a specific folder, where I put the source file, as well as the one that I use as a reference for the styles in Word; the resulting file will be in that folder.

Here are the steps I followed to change the styles in the .docx file.

1. I opened the "nnels_styles.dotx" file in Word and then I saved it with a different name "nnels_s.docx" (note that the file is now a full .docx file, no longer a template.

2. Close that file (made sure that it is in the desired folder). This file will be the reference, the styles from this file will be applied to the file we want to modify.

3. open Windows Powershell or the command line and make sure you are in the desired folder. I typed "cd documents" and press enter; because I am working in a folder which is inside the documents folder, I need to do the same to move to it and so I type "cd MyMarkdown" and pressed enter.

4. Typed the following command: "pandoc -S --reference-docx nnels_s.docx -s A_Hughes.docx -o A_Hughes2.docx"

The first.docx file is the one with the reference style; the second file is the one we want to modify; and the third .docx file is the output, so I added a 2 to distinguish it from the one containing the styles we do not want.

Using Pandoc and slightly modifying the command above, we can convert the .epub file to a .docx file, and apply the desired nnels style in one step. To do that, the three first steps would be exactly the same, the only difference would be in the fourth step, the specific command. It would be as follows:

"pandoc -S --reference-docx nnels_s.docx -o Hughes.docx Hughes.epub"

The first .docx file is the reference for the style; the second .docx file (preceded by "-o " is the result, or the output file; and the last part of the command is the source epub file that we are converting.

I hope this is useful. It took me a bit of time to be comfortable with Pandoc but I use it all the time now.

I do not mean to suggest that the resulting .docx file will be completely ready; there will still be specific things that will need to be edited but thanks to this process I was able to produce a copy of Hit the Ground Running that for the most part has the NNELS desired styles that I can now edit.

I still have to delete the style and replace it with the NNELS template from within Word.
farrah
Posts: 41
Joined: Tue Feb 06, 2018 10:50 am
Contact:

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest