The VBA StrConv function converts a string into a specified format.
The syntax of the function is:
Where the function arguments are:
String | - | The string to be converted. | |||||||||||||||||||||||||||
Conversion | - |
A VbStrConv enumerator, specifying the type of conversion that is to be made. This can be any of the following values:
|
|||||||||||||||||||||||||||
[LocaleID] | - |
An optional argument, specifying the LocaleID. If omitted, the [LCID] argument uses the system LocaleID |
The following VBA code coverts the String "TEST string" into upper, lower and proper case.
' Example 1 - Covert the String "TEST string" to upper case.
Dim str1 As String str1 = StrConv( "TEST string", vbUpperCase ) ' The String str1 is now equal to "TEST STRING".
' Example 2 - Covert the String "TEST string" to lower case.
' Example 3 - Covert the String "TEST string" to proper case.Dim str2 As String str2 = StrConv( "TEST string", vbLowerCase ) ' The String str2 is now equal to "test string". Dim str3 As String str3 = StrConv( "TEST string", vbProperCase ) ' The String str3 is now equal to "Test String". |
After running the above VBA code:
The variable str1 = "TEST STRING" (upper case); |
The variable str2 = "test string" (lower case); |
The variable str3 = "Test String" (proper case). |