I am trying to create a VBA procedure for MS Word 2010 that helps me set quotation marks in certain places, and do some additional text replacements.
I need Germany style quotation marks (lower 99 at the beginning of quote, upper 66 at the end).
(When typing manually into a document, with language set to German, MS Word automatically replaces upper straight quotation marks (") by the correct German ones. But this is of no use when inserting quotation marks via VBA procedure as this special treatment of quotation marks seems to be triggered only when the straight quotation marks are punched in via keyboard.)
Here is my code:
Sub SetInPhraseQuotation()
Dim strString As String
'Mark a certain piece of the text
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
strString = Selection
'Do some replacements in the string that are not of interest here
strString = replace(strString, Left(strString, 1), ":")
'Do some more replacment and add a lower-99-quotation mark
strString = replace(strString, Right(strString, 1), Chr(132) & UCase(Right(strString, 1)))
Selection.TypeText text:=strString
'Same result also when using
'Selection.Range.text = strString
End Sub
The documents I am working with are usually set in Times New Roman.
Here is the problem: Everything works fine, especially on fresh documents I created on my computer. However, in documents that contain text copy pasted from my colleagues' documents, the quotation marks - Chr(132) - happen to be set in a different font face (Calibri) than the surrounding text (Times New Roman in my case).
Question: How can I programmatically make sure that the quotation marks inserted - Chr(132) - are set in the same type face as the surrounding text (here: Times New Roman).
By the way: I do not understand why this is a problem at all. As the surrounding text is Times New Roman, why is inserted text Calibri out of a sudden? Especially as the other steps (various replacements) are carried out without type faces being changed. Also, I have a couple of other procedures that insert text programmatically, and there is no problem with wrong type faces. It seems, the issue is related especially to those German lower-99-style quotation marks...
Additional information, after more experiments
I tried to circumvent the issue by adding to my procedure, lazily:
Selection.MoveLeft Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Selection.Font.Name = "Times New Roman"
Selection.MoveRight
which should mark the four characters in questions and assign "Times New Roman" to them. Surprise: the Calibri quotation marks are resilient enough to be not at all affected.
When checking the various styles applied to paragraphs and letters (using the "Style Inspector") I observe that "Calibri" on these quotation marks is stated in the font selector (dropdown) in Word's menu (or do they call it Ribbon now?) solely, however at not a single other place in the Style Inspector or wherever. Simply no "Calibri" stated there. Only in the Ribbon dropdown.
Selection.TypeText
could have something to do with the font substitution as it is more likely to trigger "Format As You Type", mimicking to a certain extent user actions. Instead, trySelection.Range.Text = strString
and see if that makes a difference. Also, check the font of your document's NORMAL style (Standard Formatvorlage): is that set to Calibri (which would be Word's default) or to Times New Roman? – Cindy Meisterreplace
function? If you take that out does it make any difference? – Cindy Meister