I've been tasked with writing some VBA to combine a number of MSWord documents into a single document and format it based on certain styles in the original. One of the formatting changes is a different font. The document owner can't use styles in the final document.
My code works other than for one issue: If the paragraph is dialogue, ie it starts with an inverted comma, the new font is adopted apart from the very first inverted comma which has the default document font. Even if I set the .Range.Font property on the character, parapgraph or entire document, the default font of that inverted comma won't change. And yet it does if I manually select the text and set the font from my dropdown.
Does anyone know what I'm missing here? How do I ensure that leading inverted commas in a paragraph adopt the assigned font? The relevant parts of the code are as follows:
Dim fd As FileDialog
Dim txDoc As Document, refDoc As Document
Dim rng As Range, chr As Range
Dim para As Paragraph
Dim pt(1) As Long
Dim i As Long, p As Long
'... some code to open the files and find the relevant parts.
'Transfer the text.
'-> refDoc is the new document to which the old documents are transferred.
'-> txDoc is one of the old documents.
'-> Both are opened from a FileDialog routine.
With refDoc
.Range(.Content.End - 1, .Content.End - 1).InsertBreak wdPageBreak
pt(0) = .Content.End - 1
.Range.InsertAfter txDoc.Content.Text
pt(1) = .Content.End - 1
End With
'Set the basic format.
With refDoc.Range(pt(0), pt(1))
With .Font
.Name = "Sabon LT"
.Size = 12
End With
With .ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceDouble
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = CentimetersToPoints(1)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.CollapsedByDefault = False
End With
End With
'... some additional formatting code.