HOWTO · VBA

How to Use Quotes in Strings in VBA

Learn how to include double-quote characters in VBA strings by doubling them, using Chr(34), or storing the character in a variable.

On this page

To put a literal double quote inside a VBA string, double that quote in the string literal, concatenate Chr(34), or store the quote character in a string variable. Each approach produces the same character; choose based on which makes the surrounding text easiest to read.

How VBA Represents Quotes in String Literals

VBA string literals begin and end with double quotation marks. To include a double-quote character as part of the string, write two consecutive double quotes inside the literal. VBA interprets that pair as one character in the resulting string. The outer marks still delimit the literal.

For example, the assignment message = "She said, ""Hello, World!""" produces a string containing She said, "Hello, World!". The doubled marks in the source are syntax; they do not both appear in the value. A single quote (') can appear directly as string content, but it does not replace the double-quote delimiters used by VBA string literals.

The following standalone Python example was run successfully and produced the shown text. This confirms the Python output only; it does not execute or validate VBA syntax.

Run this Python example:

print('She said, "Hello, World!"')
She said, "Hello, World!"

Include a Quote by Doubling It

For text that is already a VBA string literal, doubling the embedded marks is usually the most direct option. The complete VBA procedure below assigns the value and displays it with a message box. It is a syntax illustration; the configured runtime does not execute VBA, so no runtime output is claimed for this procedure.

Sub ExampleUsingDoubleQuotes()
Dim message As String
message = "She said, ""Hello, World!"""
MsgBox message
End Sub

The string value contains one quote before Hello and one after World!. Keep the two source marks together for each embedded quote. This method works well when the quoted phrase is fixed and the literal remains readable. If the text is assembled from changing pieces, one of the concatenation patterns below may make the construction clearer.

Build a String with Chr(34)

Chr(34) returns the character associated with character code 34, a double quote. Concatenate that value between text fragments with VBA’s & operator. This can make the quote boundaries easier to spot when a string contains several pieces or is assembled dynamically.

This complete VBA procedure illustrates the construction and display. It is not run by the available runtime:

Sub ExampleUsingChrFunction()
Dim message As String
message = "She said, " & Chr(34) & "Hello, World!" & Chr(34)
MsgBox message
End Sub

The resulting text is the same as in the first example: She said, "Hello, World!". The & operators join the opening text, the quote character, the phrase, the second quote character, and the final text. This approach is especially handy when the pieces come from variables or other expressions. For a short fixed phrase, compare it with doubled quotes and use the form that is easiest for someone maintaining the code to follow.

Store the Quote Character in a Variable

When the same quote character is used several times, assign it once to a String variable and concatenate that variable wherever needed. To assign one double-quote character, the VBA literal itself contains a doubled pair between its delimiters: quote = """".

Here is a complete VBA syntax illustration:

Sub ExampleUsingStringVariable()
Dim quote As String
Dim message As String
quote = """"
message = "She said, " & quote & "Hello, World!" & quote
MsgBox message
End Sub

The variable names the character being reused and keeps the longer expression visually consistent. It can help when a procedure builds multiple quoted values. It does not change VBA’s string-literal syntax: string literals still use double quotes. If the desired content is a single quote, write it directly inside the double-quoted literal, such as "It's ready".

Choose a Method for Your VBA String

Use doubled quotes for a short, fixed literal because the source and result are easy to keep together. Use Chr(34) when concatenating multiple fragments makes the quote positions clearer, or when the fragments are computed. Use a quote variable when the same character appears repeatedly and giving it a name improves readability.

All three patterns construct a string containing a double quote; none changes how VBA recognizes the delimiters around a string literal. The examples above show the intended syntax and value, but they have not been executed as VBA in this environment. When adapting one, keep the delimiters balanced and inspect the assembled text in the context where your macro uses it.