📄 vba_functions.html
字号:
Constant Value Description <br> vbTrue 1 True <br> vbFalse 0 False <br> vbUseDefault 2 Use the setting from the computer's regional settings. <br> <br> <br> Remarks<br> <br> When one or more optional arguments are omitted, the values for omitted arguments are provided by the computer's regional settings.<br> <br> The position of the currency symbol relative to the currency value is determined by the system's regional settings.<br> <br> Note All settings information comes from the Regional Settings Currency tab, except leading zero which comes from the Number tab.</td><td>1</td></tr><tr><td>FormatDateTime</td><td>Returns an expression formatted as a date or time.<br> <br> Syntax<br> <br> FormatDateTime(Date[,NamedFormat])<br> <br> The FormatDateTime function syntax has these parts:<br> <br> Part Description <br> Date Required. Date expression to be formatted. <br> NamedFormat Optional. Numeric value that indicates the date/time format used. If omitted, vbGeneralDate is used. <br> <br> <br> Settings<br> <br> The NamedFormat argument has the following settings:<br> <br> Constant Value Description <br> vbGeneralDate 0 Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed. <br> vbLongDate 1 Display a date using the long date format specified in your computer's regional settings. <br> vbShortDate 2 Display a date using the short date format specified in your computer's regional settings. <br> vbLongTime 3 Display a time using the time format specified in your computer's regional settings. <br> vbShortTime 4 Display a time using the 24-hour format (hh:mm). </td><td>1</td></tr><tr><td>FormatNumber</td><td>Returns an expression formatted as a number.<br> <br> Syntax<br> <br> FormatNumber(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]])<br> <br> The FormatNumber function syntax has these parts:<br> <br> Part Description <br> Expression Required. Expression to be formatted. <br> NumDigitsAfterDecimal Optional. Numeric value indicating how many places to the right of the decimal are displayed. Default value is 1, which indicates that the computer's regional settings are used. <br> IncludeLeadingDigit Optional. Tristate constant that indicates whether or not a leading zero is displayed for fractional values. See Settings section for values. <br> UseParensForNegativeNumbers Optional. Tristate constant that indicates whether or not to place negative values within parentheses. See Settings section for values. <br> GroupDigits Optional. Tristate constant that indicates whether or not numbers are grouped using the group delimiter specified in the computer's regional settings. See Settings section for values. <br> <br> Settings<br> <br> The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits arguments have the following settings:<br> <br> Constant Value Description <br> vbTrue 1 True <br> vbFalse 0 False <br> vbUseDefault 2 Use the setting from the computer's regional settings. <br> <br> Remarks<br> <br> When one or more optional arguments are omitted, the values for omitted arguments are provided by the computer's regional settings.<br> <br> Note All settings information comes from the Regional Settings Number tab.</td><td> 1</td></tr><tr><td>FormatPercent</td><td>Returns an expression formatted as a percentage (multipled by 100) with a trailing % character.<br> <br> Syntax<br> <br> FormatPercent(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]])<br> <br> The FormatPercent function syntax has these parts:<br> <br> Part Description <br> Expression Required. Expression to be formatted. <br> NumDigitsAfterDecimal Optional. Numeric value indicating how many places to the right of the decimal are displayed. Default value is 1, which indicates that the computer's regional settings are used. <br> IncludeLeadingDigit Optional. Tristate constant that indicates whether or not a leading zero is displayed for fractional values. See Settings section for values. <br> UseParensForNegativeNumbers Optional. Tristate constant that indicates whether or not to place negative values within parentheses. See Settings section for values. <br> GroupDigits Optional. Tristate constant that indicates whether or not numbers are grouped using the group delimiter specified in the computer's regional settings. See Settings section for values.<br> <br> Settings<br> <br> The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits arguments have the following settings:<br> <br> Constant Value Description <br> vbTrue 1 True <br> vbFalse 0 False <br> vbUseDefault 2 Use the setting from the computer's regional settings. <br> <br> Remarks<br> <br> When one or more optional arguments are omitted, the values for omitted arguments are provided by the computer's regional settings.<br> <br> Note All settings information comes from the Regional Settings Number tab.</td><td> 1</td></tr><tr><td>FreeFile</td><td>Returns an Integer representing the next file number available for use by the Open statement.<br> <br> Syntax<br> <br> FreeFile[(rangenumber)]<br> <br> The optional rangenumber argument is a Variant that specifies the range from which the next free file number is to be returned. Specify a 0 (default) to return a file number in the range 1 255, inclusive. Specify a 1 to return a file number in the range 256 511.<br> <br> Remarks<br> <br> Use FreeFile to supply a file number that is not already in use.</td><td>-</td></tr><tr><td>FV</td><td>Returns a Double specifying the future value of an annuity based on periodic, fixed payments and a fixed interest rate.<br> <br> Syntax<br> <br> FV(rate, nper, pmt[, pv[, type]])<br> <br> The FV function has these named arguments:<br> <br> Part Description <br> rate Required. Double specifying interest rate per period. For example, if you get a car loan at an annual percentage rate (APR) of 10 percent and make monthly payments, the rate per period is 0.1/12, or 0.0083. <br> nper Required. Integer specifying total number of payment periods in the annuity. For example, if you make monthly payments on a four-year car loan, your loan has a total of 4 * 12 (or 48) payment periods. <br> pmt Required. Double specifying payment to be made each period. Payments usually contain principal and interest that doesn't change over the life of the annuity. <br> pv Optional. Variant specifying present value (or lump sum) of a series of future payments. For example, when you borrow money to buy a car, the loan amount is the present value to the lender of the monthly car payments you will make. If omitted, 0 is assumed. <br> type Optional. Variant specifying when payments are due. Use 0 if payments are due at the end of the payment period, or use 1 if payments are due at the beginning of the period. If omitted, 0 is assumed. <br> <br> <br> Remarks<br> <br> An annuity is a series of fixed cash payments made over a period of time. An annuity can be a loan (such as a home mortgage) or an investment (such as a monthly savings plan).<br> <br> The rate and nper arguments must be calculated using payment periods expressed in the same units. For example, if rate is calculated using months, nper must also be calculated using months.<br> <br> For all arguments, cash paid out (such as deposits to savings) is represented by negative numbers; cash received (such as dividend checks) is represented by positive numbers.</td><td>2</td></tr><tr><td>GetAllSettings</td><td>Returns a list of key settings and their respective values (originally created with SaveSetting) from an application's entry in the Windows registry.<br> <br> Syntax<br> <br> GetAllSettings(appname, section)<br> <br> The GetAllSettings function syntax has these named arguments:<br> <br> Part Description <br> appname Required. String expression containing the name of the application or project whose key settings are requested. <br> section Required. String expression containing the name of the section whose key settings are requested. GetAllSettings returns a Variant whose contents is a two-dimensional array of strings containing all the key settings in the specified section and their corresponding values. <br> <br> <br> Remarks<br> <br> GetAllSettings returns an uninitialized Variant if either appname or section does not exist.</td><td>-</td></tr><tr><td>GetAttr</td><td>Returns an Integer representing the attributes of a file, directory, or folder.<br> <br> Syntax<br> <br> GetAttr(pathname)<br> <br> The required pathname argument is a string expression that specifies a file name. The pathname may include the directory or folder, and the drive.<br> <br> Return Values<br> <br> The value returned by GetAttr is the sum of the following attribute values:<br> <br> Constant Value Description <br> vbNormal 0 Normal. <br> vbReadOnly 1 Read-only. <br> vbHidden 2 Hidden. <br> vbSystem 4 System file. <br> vbDirectory 16 Directory or folder. <br> vbArchive 32 File has changed since last backup. <br> <br> <br> Note These constants are specified by Visual Basic for Applications. The names can be used anywhere in your code in place of the actual values.<br> <br> Remarks<br> <br> To determine which attributes are set, use the And operator to perform a bitwise comparison of the value returned by the GetAttr function and the value of the individual file attribute you want. If the result is not zero, that attribute is set for the named file. For example, the return value of the following And expression is zero if the Archive attribute is not set:<br> <br> Result = GetAttr(FName) And vbArchive<br> A nonzero value is returned if the Archive attribute is set.</td><td>-</td></tr><tr><td>GetObject</td><td>Returns a reference to an object provided by an ActiveX component.<br> <br> Syntax<br> <br> GetObject([pathname] [, class])<br> <br> The GetObject function syntax has these named arguments:<br> <br> Part Description <br> pathname Optional; Variant (String). The full path and name of the file containing the object to retrieve. If pathname is omitted, class is required. <br> class Optional; Variant (String). A string representing the class of the object. <br> <br> <br> The class argument uses the syntax appname.objecttype and has these parts:<br> <br> Part Description <br> appname Required; Variant (String). The name of the application providing the object. <br> objecttype Required; Variant (String). The type or class of object to create. <br> <br> <br> Remarks<br> <br> Use the GetObject function to access an ActiveX object from a file and assign the object to an object variable. Use the Set statement to assign the object returned by GetObject to the object variable. For example:<br> <br> Dim CADObject As Object<br> Set CADObject = GetObject("C:\CAD\SCHEMA.CAD")<br> When this code is executed, the application associated with the specified pathname is started and the object in the specified file is activated.<br> <br> If pathname is a zero-length string (""), GetObject returns a new object instance of the specified type. If the pathname argument is omitted, GetObject returns a currently active object of the specified type. If no object of the specified type exists, an error occurs.<br> <br> Some applications allow you to activate part of a file. Add an exclamation point (!) to the end of the file name and follow it with a string that identifies the part of the file you want to activate. For information on how to create this string, see the documentation for the application that created the object.<br> <br> For example, in a drawing application you might have multiple layers to a drawing stored in a file. You could use the following code to activate a layer within a drawing called <br> SCHEMA.CAD<br> :<br> <br> Set LayerObject = GetObject("C:\CAD\SCHEMA.CAD!Layer3")<br> If you don't specify the object's class, Automation determines the application to start and the object to activate, based on the file name you provide. Some files, however, may support more than one class of object. For example, a drawing might support three different types of objects: an Application object, a Drawing object, and a Toolbar object, all of which are part of the same file. To specify which object in a file you want to activate, use the optional class argument. For example:<br> <br> Dim MyObject As Object<br> Set MyObject = GetObject("C:\DRAWINGS\SAMPLE.DRW", "FIGMENT.DRAWING")<br> In the example, <br> FIGMENT<br> is the name of a drawing application and <br> DRAWING<br> is one of the object t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -