0
votes

There seems to be a problem when trying to get different kinds o quote characters when replacing text:

With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "\{QUOTE:(*):QUOTE\}"
    .Replacement.Text = Chr(147) & "\1" & Chr(148)
    .Forward = True
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
End With

When the document contains: {QUOTE:abc:QUOTE}

the code gives: ”abc”

but expected result is: “abc”

Versions of Word: “Microsoft Office Professional Plus 2013” and “Microsoft Office 365 ProPlus”.

The problem does not happen when File->Options->Proofing->AutoCorrect Options->AutoFormat As You Type->Replace as you type->"Straight quotes" with “smart quotes” is not activated. Of course I want the macro to work regardless of any setting for manual typing.

How can the code be changed to get the expected result?

1
I can't reproduce your issue - what version of Word are you working out of?dwirony
Versions: “Microsoft Office Professional Plus 2013” and “Microsoft Office 365 ProPlus”. The problem does not happen when a certain checkbox is cleared; File->Options->Proofing->AutoCorrect Options->AutoFormat As You Type->Replace as you type->"Straight quotes" with “smart quotes”. Of course I want the macro to work regardless of any setting for manual typing. For now I will just keep the checkbox cleared. What it is supposed to do can be done with a regular auto-correct entry from " to ”.Erik på kontoret

1 Answers

1
votes

The way to solve this kind of problem is to turn the option off for the duration of the code, then turn it back on again if it was on.

The following code snippet saves the user's setting, turns off the option, then restores the user's setting (whether or not the option was on or off).

Dim bReplaceQuotes as Boolean
'Save the user's setting
bReplaceQuotes = Options.AutoFormatAsYouTypeReplaceQuotes
Options.AutoFormatAsYouTypeReplaceQuotes = False
'Do the FindReplace
'Restore the user's settings at the end
Options.AutoFormatAsYouTypeReplaceQuotes = bReplaceQuotes