使用时间戳保存新文件名时遇到麻烦 然后它会放入新的时间戳。
如何用新名称替换名称中的当前时间戳?
我的文件名从“ 28-11-2018 XXXXXXX”更改为“ 29-11-2018 28-11-2018 XXXXXX”
这是我的代码:
Sub workbook_save()
Dim thisWb As Workbook
Set thisWb = ActiveWorkbook
MyOldName = ActiveWorkbook.FullName
MyNewName = Format(Now, "dd-mm-yyyy") & " " & ActiveWorkbook.Name
ActiveWorkbook.SaveAs Filename:=thisWb.Path & "\" & MyNewName
Kill MyOldName
End Sub
预先感谢
答案 0 :(得分:3)
尝试一下
在fixfilename中,我将文件名的“ XXXXXX”部分设为静态值。
Sub workbook_save()
Dim thisWb As Workbook
Dim fixfilename As String
Dim newfilename As String
Set thisWb = ActiveWorkbook
fixfilename = "TESTFILE"
newfilename = Format(Now, "dd-mm-yyyy") & fixfilename
thisWb.SaveAs Filename:=thisWb.Path & "\" & newfilename
End Sub
答案 1 :(得分:0)
Format(Now, "dd-mm-yyyy")
只是将文件保存为dd-mm-yyyy-文件名中没有小时,分钟,秒的输出,将日期格式更改为dd-mm-yyyy hhmmss000。>