Is there a way to generate Word paragraph styles?

I’ve specified styles in Scrivener. But in the compiled word document, those styles are not transformed into Word paragraph styles, which means the table of contents cannot be generated automatically. And I don’t like coping TOC in Scrivener because I have to fix the page number manually afterwards. My document is about 200 pages with about 50+ paragraphs. It’s a tedious work to manually fix the page numbers.

Is there any good solution to this problem? Thanks!

There are no Paragraph Styles in Scrivener. You can apply format presets, but they don’t translate into styles.

I don’t know if in Word there is something similar to a nice feature of Nisus Writer: you place the text cursor in a heading text, choose the Select All command from the Character pop-up menu, and all similarly formatted paragraphs are selected. At this point, you can apply the relevant paragraph style.

Not as immediate as direct style support, but quite fast.

Paolo

A workaround for you might be to make some artful use of Word’s search and replace capabilities. I believe you can accomplish what you want in one step.

Basically, what you are needing to do is apply Heading styles to certain paragraphs once you get into Word. So, if you can make those paragraphs searchable in Word, you can do this in one move by Search and Replace. Actually, you will need Word’s “advanced search and replace function” (which is their new name for their old not-dumbed-down search and replace function).

So all you need is a way to “mark” each paragraph to be put in heading style in Word.

There would be many ways to do this, but what will be the right way depends on how you work, since whatever “mark” you choose needs to be a kind of mark you do not otherwise use for something already.

For simplicity, let’s suppose your TOC only has one level (non-hierarchical). You could, for example, tag your TOC-ready paragraphs by paragraph indent. Or by highlighting, say, the first words in it. Of you could front each such paragraph with a tab character (or special symbol, e.g. §). For all of these are searchable things in Word.

Then, when you compile to Word, you can use advanced search and replace to, for example, SEARCH for all § symbols and REPLACE ALL with paragraph style ‘Heading 1’. This will not actually replace the character, but will find each paragraph that has that character in it and set that paragraph to that style. (You can then do a quick Search and Replace All to actually the § characters to null strings.)

It’s a workaround for sure, but eminently doable. In fact, I guess it can be done so as to be just one additional step more than you would be doing anyway.

There are, no doubt other ways to “mark” your intended paragraphs that you could use here. An interesting one to note is search and replace by paragraph indent. This means you could do the above in a single pass, if your intended paragraph were identifiable by indent, because you can search for that inch-level of indent in Word and “replace” it with Heading 1 style – which, of course overrides the indent setting. Voila! (The indent setting(s) you need are also things you can make Scrivener paragraph presets for and attach to key commands for maximum convenience.)

-gr

And a Word macro could easily streamline the process for you.

Here, for example, is VBA code for a quick Word macro that looks for paragraph indentation in multiples of .25 inches and transforms those paragraphs into an appropriate Heading style. (Note, the macro is non-destructive – mostly because it is just proof-of-concept – so it creates a fresh document for the result rather than operating on the original.)

[code]Sub IndentToOutline()
’ This Word macro uses the currently active document as the basis for creating a new Word doc.
’ It copies each paragraph to the new document new document and sets the Outline level
’ and Heading style of any that have certain specified paragraph indents (not first line indents).
’ Optionally, is will set any remaining paragraphs in a specified custom paragraph style.

’ Notes:
’ Routine can only handle indent levels up thru 9, because that is all Word recognizes.
’ Any deeper paragraphs are left untouched (indent intact).
’ Basic formatting (bold/normal and font size) is preserved in the result doc.

'BEGIN Adjustable parameters ---------------------------------------
indentFactor = 0.25 '(in inches) paragraph indents in multiples of this will be looked for.
noIndentIsHeading1 = True 'Set to true if zero paragraph indent ought to become Heading 1 style
normalBeyondIndent = 2 'If >0, indents up to this level get Heading style, then normal paras beyond that
customNormalStyle = “” 'If not set to empty (""), all non-matching paras will get this custom style.
'END Adjustable Parameters -----------------------------------------

'get into normal view (aka draft view)
With ActiveDocument.ActiveWindow
   If .View.SplitSpecial = wdPaneNone Then
    .ActivePane.View.Type = wdNormalView
   Else
    .View.Type = wdNormalView
   End If
End With

'Create new result document
Set scrdoc = ActiveDocument
Set nodedoc = Documents.Add ' create our output document

'Walk through all the paragraphs in the source document
pcount = 0
For Each para In scrdoc.Paragraphs
    thisLine = para.Range.Text
    
    'Find the indent level of this paragraph
    icount = -1
    indentAmt = para.LeftIndent
    maxIndentToCheck = 8
    If (normalBeyondIndent > 0 And normalBeyondIndent < 9) Then maxIndentToCheck = normalBeyondIndent
    For rcount = 0 To maxIndentToCheck
        If (indentAmt = InchesToPoints(indentFactor * rcount)) Then
          icount = rcount
        End If
    Next rcount
    
    'Copy the current paragraph to the new document
    nodedoc.Content.InsertAfter (para.Range.Text)
    pcount = pcount + 1

    'Set the Style and Level, if it matches a checked indent level
    If (Not (noIndentIsHeading1)) Then icount = icount - 1
    If (icount > -1) Then
      'Set para to the appropriate Outline Level (this is distinct from the style setting)
      nodedoc.Paragraphs(pcount).OutlineLevel = icount + 1
      'Set para to the appropriate Heading Style
      If (icount = 0) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading1
      If (icount = 1) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading2
      If (icount = 2) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading3
      If (icount = 3) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading4
      If (icount = 4) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading5
      If (icount = 5) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading6
      If (icount = 6) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading7
      If (icount = 7) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading8
      If (icount = 8) Then nodedoc.Paragraphs(pcount).Style = wdStyleHeading9
    Else
        If customNormalStyle <> "" Then
            nodedoc.Paragraphs(pcount).Style = customNormalStyle
        End If
    End If
Next para

'Show the result document in Outline View (where the result of our work will be obvious).
With ActiveDocument.ActiveWindow
   If .View.SplitSpecial = wdPaneNone Then
    .ActivePane.View.Type = wdOutlineView
   Else
    .View.Type = wdOutlineView
   End If
End With

'This bit could be enabled if a Save As dialog should come up automatically.
'With Dialogs(wdDialogFileSaveAs)
  '.Format = 0   'Note: 2 = Plain Text, 0 = Word Doc
  '.Show
'End With

End Sub
[/code]

No, I am not code crazy, I just happened to have a macro that did a similar job and could be easily bent to the purpose.

-gr

Thanks everyone for your ideas!!