0

我有两行看起来非常简单的代码,但是 excel 不断给我这个编译错误,告诉我需要对象?

所以基本上我想获取当前时间,并用下划线替换空格,这样我就可以使用这个字符串作为我的日志时间的名称。

Dim name As String

'EXCEL GIVE ME compile error: object required
name = Replace(FormatDateTime(Now, DateFormat.LONGTIME), " ", "_")

怎么了?!!

4

2 回答 2

1

将 DateFormat.LONGTIME 替换为 'vbLongTime' 对我有用。

name = Replace(FormatDateTime(Now, vbLongTime), " ", "_")
于 2013-02-04T15:56:59.277 回答
1

您需要调用 Now 因为它不是变量而是过程

var now = str(Now());
name = Replace(FormatDateTime(now, DateFormat.LONGTIME), " ", "_")

应该修复它

于 2013-02-04T15:53:52.670 回答