Heading

This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
min read

Double quote functions

Word • Macros • Functions
Peter Ronhovde
5
min read

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.

Function LeftDQ() As String
' Include function steps ...

' Wait for return character below ...
End Function

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.

#If Mac Then
' Do something only in Word for Mac
#Else
' Do something else only in Word for Windows
#End If

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.

#If Mac Then
' Left double quote in Word for Mac
LeftDQ = Chr(210)
#Else
' Left double quote in Word for Windows
LeftDQ = Chr(147)
#End If

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.

Function LeftDQ() As String
' Left double quote using extended ASCII code is different on Mac and Windows.
#If Mac Then
LeftDQ = Chr(210)
#Else
LeftDQ = Chr(147)
#End If
End Function
Function RightDQ() As String
' Right double quote using extended ASCII code is different on Mac and Windows.
#If Mac Then
RightDQ = Chr(211)
#Else
RightDQ = Chr(148)
#End If
End Function

Here are the corresponding left and right single quote functions for completeness.

Function LeftSQ() As String
' Left single quote using extended ASCII code is different on Mac and Windows.
#If Mac Then
LeftSQ = Chr(212)
#Else
LeftSQ = Chr(145)
#End If
End Function
Function RightSQ() As String
' Right single quote using extended ASCII code is different on Mac and Windows.
#If Mac Then
RightSQ = Chr(213)
#Else
RightSQ = Chr(146)
#End If
End Function

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.

Function EnDash() As String
' Return an en-dash depending on the system
#If Mac Then
EnDash = Chr(208) ' en-dash in Word for Mac
#Else
EnDash = Chr(150) ' en-dash in Word for Windows
#End If
End Function
Function EmDash() As String
' Return an em-dash depending on the system
#If Mac Then
EmDash = Chr(209) ' em-dash in Word for Mac
#Else
EmDash = Chr(151) ' em-dash in Word for Windows
#End If
End Function

Affiliate Links

If you're interested in using Word or another tool related to the article, check out these affiliate links. I may make a small commission if you purchase when using them, but there is no increase in cost for you, and it helps to support this site and associated content.

I've been using Microsoft for Business for commercial use (that's us writers) on one of the lower pricing tiers for years. I get to use my macros, have online storage, and don't have to worry about software updates.