繁体   English   中英

使用VBA宏后,重新格式化日期和时间不会更改

[英]Reformatting date & time does not change after using VBA macro

我试图获取日期为mm / dd / yyyy的文件并将其重新格式化为yyyy-mm-dd并将该新格式输出到新工作表,但即使在运行我的VBS宏之后它也不会改变,尽管birthDate是正确。 我已经看到Excel存在问题,无论如何都要将格式覆盖到美国。 有没有办法解决? 谢谢!

birthDate = Trim(CStr(Sheet1.Cells(currRawRow, "F")))
    checkInput = InStr(1, birthDate, "/")

If (checkInput > 0) Then
birthYear = Year(birthDate)
birthMonth = Month(birthDate)
birthDay = Day(birthDate)

birthMonth = Format(CStr(birthMonth), "00")
birthDay = Format(CStr(birthDay), "00")
birthYear = Format(CStr(birthYear), "0000")

birthDate = (birthYear & "-" & birthMonth & "-" & birthDay)

Excel确认为日期的任何数字都将以控制面板区域设置的短日期格式显示 - >打开文件的任何人的日期和时间。

要覆盖它,要么:1)将显示的格式显式设置为Daimian建议的循环的一部分;或者; 2)强制格式为字符串,在日期前面加一个引号。

例如,在最后一行代码更改中:

birthDate =(birthYear&“ - ”&birthMonth&“ - ”&birthDay)

birthDate =“'”&(birthYear&“ - ”&birthMonth&“ - ”&birthDay)

暂无
暂无

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

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