美文网首页
VBA 学习笔记2 - 时间操作的例子

VBA 学习笔记2 - 时间操作的例子

作者: 赵阳_c149 | 来源:发表于2020-02-20 16:50 被阅读0次

取得当前时间

Dim currentDate As Date
currentDate = Now()

取得上个月的天数

Function getNumOfDaysInLastMonth(ByVal targetDate As Date) As Integer
    ' get the num of days in the last month of target date
 
    Dim currentYear As Integer
    Dim currentMonth As Integer
    Dim firstDayOfCurrentMonth As Date
    currentYear = Year(targetDate)
    currentMonth = Month(targetDate)

    firstDayOfCurrentMonth = CDate(currentYear & "-" & currentMonth & "-1")
    firstDayOfLastMonth = DateAdd("m", -1, firstDayOfCurrentMonth)

    getNumOfDaysInLastMonth = DateDiff("d", firstDayOfLastMonth, firstDayOfCurrentMonth)
End Function

参考
时间函数

相关文章

  • VBA 学习笔记2 - 时间操作的例子

    取得当前时间 取得上个月的天数 参考时间函数

  • VBA学习笔记-02

    VBA学习笔记 笔记摘抄自EXCEL精英培训-蓝色幻想 VBA学习笔记01(链接)VBA学习笔记02 (链接) 目...

  • VBA学习笔记-01

    VBA学习笔记 笔记摘抄自EXCEL精英培训-蓝色幻想 VBA学习笔记01(链接)VBA学习笔记02 (链接) 目...

  • VBA——Worksheet操作

    VBA操作Excel中常用对象Worksheet的方法笔记,所有内容均来源于别怕,Excel VBA其实很简单。 ...

  • VBA——Range操作

    VBA操作Excel中常用对象Range的方法笔记,所有内容均来源于别怕,Excel VBA其实很简单。 Rang...

  • VBA例子

    1、查找指定单元格中的指定内容

  • VBA循环Excel文件并另存为.xlsx

    最近在学习VBA,因为工作中有很多重复的操作太过于消耗时间,过年假期基本没太出门,研究了一个星期的VBA算是入了门...

  • VBA 学习笔记4 - 操作excel文件

    打开workbook和Sheet 为单元格赋值 关闭workbook 循环

  • vba学习:文件操作

    引言 为题高办公效率,经常用到文件复制,移动,删除,重命名等操作,这次分享一下vba中的文件操作常用代码。 代码 ...

  • vba学习笔记

    Option Explicit Public Sub VBF1() MsgBox "this is my fris...

网友评论

      本文标题:VBA 学习笔记2 - 时间操作的例子

      本文链接:https://www.haomeiwen.com/subject/amgxqhtx.html