4

I want to include an XML schema in a technical document created in MS Word. It has lines which are much longer than the available width on the page, so Word automatically breaks the lines. I want to make it explicitly clear to the reader where this has happened, so they know the next line is a continuation of the previous one. Is there a way to cause Word to automatically insert a symbol, for instance ⏎, at the end of each automatically broken line?

I could of course do it manually, but that would be a lot of work which I would have to repeat every time the schema changes, and it would be error prone. I know about the "show non-printing characters" mode, but I want these symbols to only be visible in this section, and to be printed as well. Besides, "show non-printing characters" shows the explicit line breaks instead of the automatic ones.

Is this possible with MS Word, or if not, can someone recommend another automated technique for achieving it?

2 Answers2

0

I won't put it as a duplicate, because it's not an answered question, but might want to look here:
Is it possible to set a style to show line continuations in Microsoft Word?

which leads you to : Convert HTML to image

Madball73
  • 2,590
0

Well, you could try the following VBA as a starting point, but I think it will need some work. It assumes that your breaks are always going to be after a space (not unreasonable for a schema IMO) so if you have spaceless text longer than a line you might still have to break those by hand.

This replaces final spaces by the return symbol in the current font + a no-width breaking space, so as long as you can adjust the width of the return symbol (there are various possible ways to do that) so that Word still wraps at the same points, it may be enough.

Sub markAutoLineBreaks()
' Changes line breaks automatically made by Word
' into "return" charaters, but only where the line
' ends in a " "
' This operates on the text in the current selection
' We use a character style
Const strStyleName As String = "contchar"
Dim r As Word.Range
Dim styContchar As Word.Style

' Add the style if it is not present
On Error Resume Next
Set styContchar = ActiveDocument.Styles.Add(strStyleName, Type:=WdStyleType.wdStyleTypeCharacter)
Err.Clear
On Error GoTo 0
' Set the characteristics of the style. What you need to aim for
' is to adjust the character width so that the text breaks at the
' same point (if possible)
Set styContchar = ActiveDocument.Styles(strStyleName)
With styContchar.Font
  .Size = 8
End With

' Save the selection
Set r = Selection.Range

' remove old line end marks
With Selection.Find
  .ClearFormatting
  .Style = styContchar
  .Replacement.ClearFormatting
  ' Not sure what to use here, but this will have to do
  .Replacement.Style = ActiveDocument.Styles("Default Paragraph Font")
  ' 9166 is the return character. 8204 is a No-width breaking space
  .Text = ChrW(9166) & ChrW(8204)
  .Replacement.Text = " "
  .Forward = True
  .Format = True
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Moving down lines is not completely straightforward
' but this seems to work
Selection.Collapse direction:=wdCollapseStart
Do Until Selection.End > r.End
  Selection.Bookmarks("\line").Select
  If Right(Selection, 1) = " " Then
      Selection.SetRange Selection.End - 1, Selection.End
      Selection.Delete
      Selection.Text = ChrW(9166) & ChrW(8204)
      Selection.Style = styContchar
      Selection.Bookmarks("\line").Select
      Selection.Collapse direction:=wdCollapseStart
  End If
  Selection.MoveDown wdLine, 1, False
Loop

' reselect our original selection
r.Select
Set r = Nothing
End Sub
phuclv
  • 30,396
  • 15
  • 136
  • 260