Like Excel, VBA can manipulate both numbers and text (strings). There are two types of strings in VBA:
♦ Fixed-length strings are declared with a specified number of characters. The maximum length is 65,535 characters.
♦ Variable-length strings theoretically can hold up to 2 billion characters.
Each character in a string requires 1 byte of storage, and a small additional amount of storage is used for the header of each string. When you declare a string variable with a Dim statement, you can specify the length if you know it (that is, a fixed-length string), or you can let VBA handle it dynamically (a variable-length string).
In the following example, the MyString variable is declared to be a string with a maximum length of 50 characters. YourString is also declared as a string, but its length is unfixed.
Dim MyString As String * 50 Dim YourString As String
Was this article helpful?