上个月名称的 VBA 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43662262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Code for name of previous month
提问by wasimakram101
I have added text in to my email that goes like:
我在我的电子邮件中添加了如下文字:
"please provide numbers for MMMM month end" - where MMMM is the name of the previous month.
“请提供 MMMM 月末的数字” - 其中 MMMM 是上个月的名称。
So it it's April today, MMMM will show March.
所以今天是四月,MMMM 将显示三月。
I have the following code:
我有以下代码:
Dim newDate: newDate = DateAdd("M", -1, Now)
But the result comes out to be 27/03/2017 16:37:58
但结果出来是 27/03/2017 16:37:58
I want it to show March.
我想让它显示三月。
Any suggestions?
有什么建议?
回答by Scott Craner
Format the return as "MMMM"
:
将返回格式设置为"MMMM"
:
Dim newDate: newDate = Format(DateAdd("M", -1, Now), "MMMM")
回答by Kostas K.
If set to True, the month name is abbreviated e.g. Apr
如果设置为 True,月份名称将缩写为 Apr
newDate = MonthName(Month(DateAdd("m", -1, Date)), False)