Excel VBA对象必需错误
我有两行代码,看起来非常简单,但excel不断给我这个编译错误,告诉我对象是必需的 所以基本上我想得到当前时间,并用下划线替换空格,这样我就可以使用这个字符串作为日志fime的名称Excel VBA对象必需错误,excel,vba,Excel,Vba,我有两行代码,看起来非常简单,但excel不断给我这个编译错误,告诉我对象是必需的 所以基本上我想得到当前时间,并用下划线替换空格,这样我就可以使用这个字符串作为日志fime的名称 Dim name As String 'EXCEL GIVE ME compile error: object required name = Replace(FormatDateTime(Now, DateFormat.LONGTIME), " ", "_") 怎么了 您现在需要调用,因为它不是一个变量,而是一
Dim name As String
'EXCEL GIVE ME compile error: object required
name = Replace(FormatDateTime(Now, DateFormat.LONGTIME), " ", "_")
怎么了 您现在需要调用,因为它不是一个变量,而是一个过程
var now = str(Now());
name = Replace(FormatDateTime(now, DateFormat.LONGTIME), " ", "_")
应该修复它将DateFormat.LONGTIME替换为“vbLongTime”对我来说很有效
name = Replace(FormatDateTime(Now, vbLongTime), " ", "_")
你的建议抛出了与初始Q相同的错误。请参阅@SoulDZIN的答案-它有效。