Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两行看起来非常简单的代码,但是 excel 不断给我这个编译错误,告诉我需要对象?
所以基本上我想获取当前时间,并用下划线替换空格,这样我就可以使用这个字符串作为我的日志时间的名称。
Dim name As String 'EXCEL GIVE ME compile error: object required name = Replace(FormatDateTime(Now, DateFormat.LONGTIME), " ", "_")
怎么了?!!
将 DateFormat.LONGTIME 替换为 'vbLongTime' 对我有用。
name = Replace(FormatDateTime(Now, vbLongTime), " ", "_")
您需要调用 Now 因为它不是变量而是过程
var now = str(Now()); name = Replace(FormatDateTime(now, DateFormat.LONGTIME), " ", "_")
应该修复它