Show All

# FormatString Method

Formats the specified string or XML node according to the specified category and options parameters.

expression.FormatString(ByVal varInput, ByVal bstrCategory As String, ByVal bstrOptions As String) As String

expression Required. An expression that returns a reference to the Application object.

varInput Required String or XML node. The string value or XML node to be formatted.

bstrCategory Required String. The string value that specifies the category used for formatting. Values include number, percentage, currency, date, time, and datetime.

bstrOptions Required String. The string value that specifies the options used for formatting. Takes the form of a case-sensitive string in the format "optionName:value".

returns String.

## Security Level

0: Can be accessed without restrictions.

## Remarks

The FormatString method can be used anywhere in your scripting code in which you need to change the format of a specified string. It must be qualified with the Application object name, and its return value must be assigned to a variable or used as an expression that requires a string value.

The following sections list the values that may be used for the bstrCategory and bstrOptions parameters:

List of categories

Name | Description
--- | ---
number | Uses numerical values. Valid options for this category include locale, numDigits, leadingZero, grouping, decimalSep, thousandSep, and negativeOrder.
percentage | Uses percentage values. Valid options for this category include locale, numDigits, leadingZero, grouping, decimalSep, thousandSep, and negativeOrder.
currency | Uses currency values. Valid options for this category include locale, numDigits, leadingZero, grouping, decimalSep, thousandSep, negativeOrder, positiveOrder, and currencyLocale.
date | Uses date values. Valid options for this category include locale, dateFormat, useAltCalendar, and useEnglishStringsAlways.
time | Uses time values. Valid options for this category include locale, timeFormat, and noSeconds.
datetime | Uses datetime values. Valid options for this category include locale, dateFormat, timeFormat, noSeconds, useAltCalendar, and useEnglishStringAlways.

List of options

Name | Description
--- | ---
locale | Specifies the locale identifier (LCID). Defaults to the current user's LCID if not specified.
numDigits | Specifies the number of fractional digits after the decimal separator. The value auto may also be used to indicate that the number of decimal places that was entered will be the number of decimal places in the output. For example, 1.234, 1.234, 1.00, 1.00, 1.56e2, or 156.00. Defaults to the corresponding value in regional settings if not specified.
leadingZero | Specifies whether to use leading zeros in decimal fields. Specify 0 to indicate no leading zeros and 1 to indicate leading zeros. Defaults to the corresponding value in regional settings if not specified.
grouping | Specifies the size of each group of digits to the left of the decimal. Values in the range 0–9 and value 32 are valid. Value 32 indicates that the grouping is three digits, then two digits thereafter. Defaults to the corresponding value in regional settings if not specified.
decimalSep | Specifies the decimal separator string. Defaults to the corresponding value in regional settings if not specified.
thousandSep | Specifies the thousands separator string. Defaults to the corresponding value in regional settings if not specified.
negativeOrder | Specifies the negative number mode. Defaults to the corresponding value in regional settings if not specified.
positiveOrder | Specifies the positive number mode. Defaults to the corresponding value in regional settings if not specified.
currencyLocale | Specifies the locale identifier (LCID) for the currency symbol. Defaults to the value specified by locale if not specified.
dateFormat | Specifies a format picture string that is used to form the date string. The values Short Date, Long Date, Year Month, and none may also be used to indicate short date format, long date format, year month format, and no format, respectively. Short Date, Long Date, and Year Month are the default formats provided by the operating system's regional and language settings.
useAltCalendar | Specifies whether to use an alternate calendar for date formatting. Specify 0 to use the normal calendar and 1 to use the alternate calendar. Defaults to 0 if not specified.
useEnglishStringsAlways | Specifies whether to always use English strings for date formatting. Specify 0 to use the language specified by locale and 1 to always use English. Defaults to 0 if not specified.
timeFormat | Specifies a format string that is used to form the time string. The value none may also be used to indicate no format. Defaults to the time format in regional settings if not specified.
noSeconds | Specifies whether to not use seconds. Specify 0 to use seconds and 1 to not use seconds. Defaults to 0 if not specified.

## Example

In the following example, the FormatString method of the Application object is used to format the specified date string into a long date format:

    Application.FormatString("2003-01-08", "date", "dateFormat:Long Date");

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp