简体   繁体   English

VBA日期格式 - 月/日/年

[英]VBA Date Format - month/day/year

I want to produce todays date like this: 01/23/2016 month/day/year. 我想生产今天这样的日期:01/23/2016月/日/年。 I wrote the below code but the result is 23/01/2016. 我写了下面的代码但结果是2016年1月23日。 Can anyone help me? 谁能帮我? Thanks 谢谢

ActiveSheet.Cells(1, 2) = Format(Date, "mm/dd/yyyy") ActiveSheet.Cells(1,2)=格式(日期,“mm / dd / yyyy”)

The code you use enters something into an Excel cell. 您使用的代码会在Excel单元格中输入内容。 Excel recognises that it is a date and will display the date according to the default settings. Excel识别出它是一个日期,并将根据默认设置显示日期。

In order to display the date with your preferred format, you need to format the cell that displays the date, not the data entry string. 要以首选格式显示日期,您需要格式化显示日期的单元格 ,而不是数据条目字符串。

ActiveSheet.Cells(1, 2) = Date
ActiveSheet.Cells(1, 2).NumberFormat = "mm/dd/yyyy"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM