VBA Code for name of previous month

余生颓废 提交于 2019-12-11 16:44:30

问题


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.

So it it's April today, MMMM will show March.

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

I want it to show March.

Any suggestions?


回答1:


Format the return as "MMMM":

Dim newDate: newDate = Format(DateAdd("M", -1, Now), "MMMM")



回答2:


If set to True, the month name is abbreviated e.g. Apr

newDate = MonthName(Month(DateAdd("m", -1, Date)), False)


来源:https://stackoverflow.com/questions/43662262/vba-code-for-name-of-previous-month

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!