我试图获得今天的VBA日期的年份和月份,我曾尝试和下面是我的代码:VBA-获取月份和年份从今天日期
Sub automation()
Dim wsheet As Worksheet
Dim month As Integer
Dim year As Integer
Set wsheet = Application.Workbooks("try").Worksheets("try")
month = Application.WorksheetFunction.month(Date)
year = Application.WorksheetFunction.year(Date)
End Sub
我不知道在哪里出错了,谁能帮忙? 如果今天的日期是2017年5月15日,我的预期产出为5月份和2017年。谢谢!
'Month'和'年'是'VBA.DateTime'模块中的函数,不保留;-) –
@ Mat'sMug - 谢谢,编辑。 – Vityata