📄 vba_functions.html
字号:
specified part of a given date.<br> <br> Syntax<br> <br> DatePart(interval, date[,firstdayofweek[, firstweekofyear]])<br> <br> The DatePart function syntax has these named arguments:<br> <br> Part Description <br> interval Required. String expression that is the interval of time you want to return. <br> date Required. Variant (Date) value that you want to evaluate. <br> firstdayofweek Optional. A constant that specifies the first day of the week. If not specified, Sunday is assumed. <br> firstweekofyear Optional. A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. <br> <br> Settings<br> <br> The interval argument has these settings:<br> <br> Setting Description <br> yyyy Year <br> q Quarter <br> m Month <br> y Day of year <br> d Day <br> w Weekday <br> ww Week <br> h Hour <br> n Minute <br> s Second <br> <br> The firstdayofweek argument has these settings:<br> <br> Constant Value Description <br> vbUseSystem 0 Use the NLS API setting. <br> vbSunday 1 Sunday (default) <br> vbMonday 2 Monday <br> vbTuesday 3 Tuesday <br> vbWednesday 4 Wednesday <br> vbThursday 5 Thursday <br> vbFriday 6 Friday <br> vbSaturday 7 Saturday <br> <br> The firstweekofyear argument has these settings:<br> <br> Constant Value Description <br> vbUseSystem 0 Use the NLS API setting. <br> vbFirstJan1 1 Start with week in which January 1 occurs (default). <br> vbFirstFourDays 2 Start with the first week that has at least four days in the new year. <br> vbFirstFullWeek 3 Start with first full week of the year. <br> <br> Remarks<br> <br> You can use the DatePart function to evaluate a date and return a specific interval of time. For example, you might use DatePart to calculate the day of the week or the current hour.<br> <br> The firstdayofweek argument affects calculations that use the "w" and "ww" interval symbols.<br> <br> If date is a date literal, the specified year becomes a permanent part of that date. However, if date is enclosed in double quotation marks (" "), and you omit the year, the current year is inserted in your code each time the date expression is evaluated. This makes it possible to write code that can be used in different years.<br> <br> Note For date, if the Calendar property setting is Gregorian, the supplied date must be Gregorian. If the calendar is Hijri, the supplied date must be Hijri.<br> <br> The returned date part is in the time period units of the current Arabic calendar. For example, if the current calendar is Hijri and the date part to be returned is the year, the year value is a Hijri year.</td><td>1</td></tr><tr><td>DateSerial</td><td>Returns a Variant (Date) for a specified year, month, and day.<br> <br> Syntax<br> <br> DateSerial(year, month, day)<br> <br> The DateSerial function syntax has these named arguments:<br> <br> Part Description <br> year Required; Integer. Number between 100 and 9999, inclusive, or a numeric expression. <br> month Required; Integer. Any numeric expression. <br> day Required; Integer. Any numeric expression. <br> <br> <br> Remarks<br> <br> To specify a date, such as December 31, 1991, the range of numbers for each DateSerial argument should be in the accepted range for the unit; that is, 131 for days and 112 for months. However, you can also specify relative dates for each argument using any numeric expression that represents some number of days, months, or years before or after a certain date.<br> <br> The following example uses numeric expressions instead of absolute date numbers. Here the DateSerial function returns a date that is the day before the first day (<br> 1 - 1<br> ), two months before August (<br> 8 - 2<br> ), 10 years before 1990 (<br> 1990 - 10<br> ); in other words, May 31, 1980.<br> <br> DateSerial(1990 - 10, 8 - 2, 1 - 1)<br> Under Windows 98 or Windows 2000, two digit years for the year argument are interpreted based on user-defined machine settings. The default settings are that values between 0 and 29, inclusive, are interpreted as the years 20002029. The default values between 30 and 99 are interpreted as the years 19301999. For all other year arguments, use a four-digit year (for example, 1800). <br> <br> Earlier versions of Windows interpret two-digit years based on the defaults described above. To be sure the function returns the proper value, use a four-digit year.<br> <br> When any argument exceeds the accepted range for that argument, it increments to the next larger unit as appropriate. For example, if you specify 35 days, it is evaluated as one month and some number of days, depending on where in the year it is applied. If any single argument is outside the range -32,768 to 32,767, an error occurs. If the date specified by the three arguments falls outside the acceptable range of dates, an error occurs.<br> <br> Note For year, month, and day, if the Calendar property setting is Gregorian, the supplied value is assumed to be Gregorian. If the Calendar property setting is Hijri, the supplied value is assumed to be Hijri.<br> <br> The returned date part is in the time period units of the current Visual Basic calendar. For example, if the current calendar is Hijri and the date part to be returned is the year, the year value is a Hijri year. For the argument year, values between 0 and 99, inclusive, are interpreted as the years 1400-1499. For all other year values, use the complete four-digit year (for example, 1520).</td><td>1</td></tr><tr><td>DateValue</td><td>Returns a Variant (Date).<br> <br> Syntax<br> <br> DateValue(date)<br> <br> The required date argument is normally a string expression representing a date from January 1, 100 through December 31, 9999. However, date can also be any expression that can represent a date, a time, or both a date and time, in that range.<br> <br> Remarks<br> <br> If date is a string that includes only numbers separated by valid date separators, DateValue recognizes the order for month, day, and year according to the Short Date format you specified for your system. DateValue also recognizes unambiguous dates that contain month names, either in long or abbreviated form. For example, in addition to recognizing 12/30/1991 and 12/30/91, DateValue also recognizes December 30, 1991 and Dec 30, 1991.<br> <br> If the year part of date is omitted, DateValue uses the current year from your computer's system date.<br> <br> If the date argument includes time information, DateValue doesn't return it. However, if date includes invalid time information (such as "89:98"), an error occurs.<br> <br> Note For date, if the Calendar property setting is Gregorian, the supplied date must be Gregorian. If the calendar is Hijri, the supplied date must be Hijri. If the supplied date is Hijri, the argument date is a String representing a date from 1/1/100 (Gregorian Aug 2, 718) through 4/3/9666 (Gregorian Dec 31, 9999).</td><td>1</td></tr><tr><td>Day</td><td>Returns a Variant (Integer) specifying a whole number between 1 and 31, inclusive, representing the day of the month.<br> <br> Syntax<br> <br> Day(date)<br> <br> The required date argument is any Variant, numeric expression, string expression, or any combination, that can represent a date. If date contains Null, Null is returned.<br> <br> Note If the Calendar property setting is Gregorian, the returned integer represents the Gregorian day of the month for the date argument. If the calendar is Hijri, the returned integer represents the Hijri day of the month for the date argument.</td><td>1</td></tr><tr><td>DDB</td><td>Returns a Double specifying the depreciation of an asset for a specific time period using the double-declining balance method or some other method you specify.<br> <br> Syntax<br> <br> DDB(cost, salvage, life, period[, factor])<br> <br> The DDB function has these named arguments:<br> <br> Part Description <br> cost Required. Double specifying initial cost of the asset. <br> salvage Required. Double specifying value of the asset at the end of its useful life. <br> life Required. Double specifying length of useful life of the asset. <br> period Required. Double specifying period for which asset depreciation is calculated. <br> factor Optional. Variant specifying rate at which the balance declines. If omitted, 2 (double-declining method) is assumed. <br> <br> <br> Remarks<br> <br> The double-declining balance method computes depreciation at an accelerated rate. Depreciation is highest in the first period and decreases in successive periods.<br> <br> The life and period arguments must be expressed in the same units. For example, if life is given in months, period must also be given in months. All arguments must be positive numbers.<br> <br> The DDB function uses the following formula to calculate depreciation for a given period:<br> <br> Depreciation / period = ((cost salvage) * factor) / life</td><td>2</td></tr><tr><td>Dir</td><td>Returns a String representing the name of a file, directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.<br> <br> Syntax<br> <br> Dir[(pathname[, attributes])]<br> <br> The Dir function syntax has these parts:<br> <br> Part Description <br> pathname Optional. String expression that specifies a file name may include directory or folder, and drive. A zero-length string ("") is returned if pathname is not found. <br> attributes Optional. Constant or numeric expression, whose sum specifies file attributes. If omitted, returns files that match pathname but have no attributes.<br> <br> Settings<br> <br> The attributes argument settings are:<br> <br> Constant Value Description <br> vbNormal 0 (Default) Specifies files with no attributes. <br> vbReadOnly 1 Specifies read-only files in addition to files with no attributes. <br> vbHidden 2 Specifies hidden files in addition to files with no attributes. <br> VbSystem 4 Specifies system files in addition to files with no attributes. <br> vbVolume 8 Specifies volume label; if any other attributed is specified, vbVolume is ignored. <br> vbDirectory 16 Specifies directories or folders in addition to files with no attributes.<br> <br> Note These constants are specified by Visual Basic for Applications and can be used anywhere in your code in place of the actual values..<br> <br> Remarks<br> <br>Dir supports the use of multiple character (*) and single character (?) wildcards to specify multiple files.</td><td>-</td></tr><tr><td>DoEvents</td><td>Yields execution so that the operating system can process other events.<br> <br> Syntax<br> <br> DoEvents( )<br> <br> Remarks<br> <br> The DoEvents function returns an Integer representing the number of open forms in stand-alone versions of Visual Basic, such as Visual Basic, Professional Edition. DoEvents returns zero in all other applications.<br> <br> DoEvents passes control to the operating system. Control is returned after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent.<br> <br> DoEvents is most useful for simple things like allowing a user to cancel a process after it has started, for example a search for a file. For long-running processes, yielding the processor is better accomplished by using a Timer or delegating the task to an ActiveX EXE component.. In the latter case, the task can continue completely independent of your application, and the operating system takes case of multitasking and time slicing.<br> <br> Caution Any time you temporarily yield the processor within an event procedure, make sure the procedure is not executed again from a different part of your code before the first call returns; this could cause unpredictable results. In addition, do not use DoEvents if other applications could possibly interact with your procedure in unforeseen ways during the time you have yielded control.</td><td>-</td></tr><tr><td>DeleteSetting</td><td> </td><td> </td></tr><tr><td>Description</td><td> </td><td> </td></tr><tr><td>Environ</td><td>Returns the String associated with an operating system environment variable. <br> <br> Syntax<br> <br> Environ({envstring | number})<br> <br> The Environ function syntax has these named arguments:<br> <br> Part Description <br> envstring Optional. String expression containing the name of an environment variable. <br> number Optional. Numeric expression corresponding to the numeric order of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -