Left and right double quotes are special characters in Word, but they unfortunately differ between Word for Mac or Windows. These functions allow us to write other general macros using double quotes without having to adjust the macros to account for different computer systems.
Thanks for your interest
This content is part of a paid plan.
Return System Dependent Characters
We build several simple functions to streamline our previous move sentence macro, but this one finds uses in multiple other macros.
Left and right double quotes are called smart double quotes in Word because Word will automatically adjust them depending on the document context. Unlike the regular straight double quotes, they are special characters, but the specific constant values unfortunately differ between Word for Mac or Windows. These functions allow us to write general macros using double quotes without having to manually change them to work correctly on different computer systems.
Different characters
The various double quote characters are: Left double quote is Chr(210) in Word for Mac but Chr(147) on Windows. Similarly, a right double quote is Chr(211) in Word for Mac and Chr(148) on Windows.
The corresponding left and right single quote characters are: Left single quote is Chr(212) in Word for Mac but Chr(145) on Windows. A right single quote is Chr(213) in Word for Mac and Chr(146) on Windows.
Create function skeleton
To create our double quote functions, we need a function declaration.
What parameter to use?
There is no function parameter since we’re just returning a known double quote character that happens to differ by operating system, so we leave the parentheses empty.
Return value
A double quote is a character. While VBA does have a dedicated character data type, it’s just more convenient to just return a string (plain text) with a one-character length. As such, we add “As String” after the Function name.
Compiler directives
To accomplish our task, we need some compiler directives. That is fancy speak for special statements that the VBA compiler (which creates the code you run) uses to make changes to your macro even before creating the macro for Word to execute on your document.
Fortunately, the directives we need are very similar to regular If Else statements in VBA.
The main difference compared to an If Else statement in VBA is the hashtag # before the If, Else, and End If statements. As a user, we don't notice much else.
Picking the correct character
We just need to assign the function name which the string value our function returns to the calling macro. We place the respective constant mentioned above inside the correct section of the compiler directive.
And so forth for the corresponding, right double quote function. I’ve also included the single quote variations if you need them.
Final Functions
The final functions are almost trivial except that they make use of complier directives to pick the correct operating system but without any additional effort on your part.
Here are the corresponding left and right single quote functions for completeness.
These functions are nice since you can create macros that use left or right double or single quotes and not worry about what computer you’re working on at the time. As long as you have your macros, you’re good.
They also make your macros easier to read since you don’t have to remember what Chr(210) means at some point in the future as opposed to LeftDQ.
Long dashes
Long dashes are also special characters in Word that differ between Mac and Windows systems.
Specifically, an en-dash has the approximate width of the letter n, and an em-dash has the approximate width of the letter m.