A string is a sequence of characters.
VBA has two types of strings:
Dim MyString As String * 50 'it is a fix-length string Dim YourString As String 'it is a variable-length string
a = "Go" b = "away!"We can paste (concatenate) the strings together using the operator &:
c = a & bThe value stored in c would be "Goaway!".
c = a & " " & b
MsgBox c
fullName = "Doe, Jane"The number of characters in this string (including blanks and punctuation marks) can be found using the Len function
length = Len(fullName)Here length would be equal to 9. The position of the comma can be found using the InStr function:
commaPosition = InStr(fullName, ",")The first argument of the InStr function specifies the string being searched and the second argument is the string sought. Since the comma is located in the fourth position, commaPosition would have a value of 4.
familyName = Left(fullName, commaPosition - 1)The Right function could be used to obtain the given name:
givenName = Right(fullName, length - commaPosition -1)The family name and the given name can be concatenated with a few phrases to display a personalized message:
MsgBox "Dear " & givenName & " " & familyName & ", How are you?"The resulting message would be:
Dear Jane Doe, How are you?