gpt4 book ai didi

excel - VBA 日期 : Cannot Get the Format Correct

转载 作者:行者123 更新时间:2023-12-04 21:59:09 24 4
gpt4 key购买 nike

我正在尝试将日期从诸如月/日/年之类的日期转换为完全拼写出来的日期,例如 2014 年 5 月 31 日。

我遇到了路障。目前,我正在使用它,当弹出消息框时,如果有正确的日期(2014 年 5 月 31 日),但是一旦我将其写入单元格,它就会转换为数字(从 14 年 5 月 31 日到41790)。我迷路了,希望得到一些帮助。谢谢!

Dim whatever as String
whatever = Format("5/31/14","mmmm dd, yyyy")
MsgBox whatever
ActiveWorkbook.Activesheet.Cells(1,1) = whatever

我有一个程序,它使用工作表中的数据在 word 中运行邮件合并,所以我试图写出整个日期,而不仅仅是简单地格式化单元格,因为 Word 获取原始数据(据我所知.)

最佳答案

当您尝试在单元格中显示格式时,正确的方法是更改​​单元格的数字格式,然后设置单元格的值

例如

Cells(1,1).NumberFormat="MMM DD, YYYY"
Cells(1,1).Value2= Date

关于excel - VBA 日期 : Cannot Get the Format Correct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38377061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com