The VBA StrConv Function

Related Functions:
VBA UCase
VBA LCase

Description

The VBA StrConv function converts a string into a specified format.

The syntax of the function is:

StrConv( String, Conversion, [LocaleID] )

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:

vbUpperCase-Convert to upper case characters.
vbLowerCase-Convert to lower case characters.
vbProperCase-Convert the first character of every word to upper case and all other characters to lower case.
vbWide-Convert narrow (single-byte) characters to wide (double-byte) characters (applies to East Asia locales only).
vbNarrow-Convert wide (double-byte) characters to narrow (single-byte) characters (applies to East Asia locales only).
vbKatakana-Convert Hiragana characters to Katakana characters (applies to Japan only).
vbHiragana-Convert Katakana characters to Hiragana characters (applies to Japan only).
vbUnicode-Convert to Unicode using the default code page of the system (not available on the Macintosh).
vbFromUnicode-Convert from Unicode to the default code page of the system (not available on the Macintosh).
[LocaleID]-

An optional argument, specifying the LocaleID.

If omitted, the [LCID] argument uses the system LocaleID



VBA StrConv Function Examples

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.
Dim str2 As String
str2 = StrConv( "TEST string", vbLowerCase )
' The String str2 is now equal to "test string".
' Example 3 - Covert the String "TEST string" to proper case.
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).