String data type
There are two kinds of strings: variable-length and fixed-length strings.
A variable-length string can contain up to approximately 2 billion (2^31) characters.
A fixed-length string can contain 1 to approximately 64 K (2^16) characters.
Note
A Public fixed-length string can't be used in a class module.
The codes for String characters range from 0–255. The first 128 characters (0–127) of the character set correspond to the letters and symbols on a standard U.S. keyboard. These first 128 characters are the same as those defined by the ASCII character set. The second 128 characters (128–255) represent special characters, such as letters in international alphabets, accents, currency symbols, and fractions.
The type-declaration character for String is the dollar ($) sign.
A double-quotation-mark can be embedded within a string literal in one of two ways:
Use two double-quotation-marks:
Dim s As String s = "This string literal has an embedded "" in it."
Use the Chr function; character code 34 is a double-quotation-mark:
Dim s As String s = "This string literal has an embedded " & Chr(34) & " in it."
A fixed-length string includes appended spaces or truncates as necessary:
Dim s As String * 3
Debug.Print Len(s) & " characters [" & s & "]" 'Prints 3 characters [ ]
s = "a"
Debug.Print Len(s) & " characters [" & s & "]" 'Prints 3 characters [a ]
s = "abcdefghijklmnopqrstuvwxyz"
Debug.Print Len(s) & " characters [" & s & "]" 'Prints 3 characters [abc]
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기