簡體   English   中英

附加用戶名和日期以在VBA中另存為

[英]Appending Username and Date to Save As in VBA

如何使用VBA代碼保存Excel文件,以便在宏中附加用戶名和日期?

這是我嘗試使其工作的代碼:

ActiveWorkbook.SaveAs FileName:=(Environ$("Username")) & "_" & Date & "_BKMtracker.xlsx", FileFormat:=xlOpenXMLWorkbook

嘗試這個:-

ActiveWorkbook.SaveAs文件名:=(Environ $(“用戶名”))&“ _”&日期&“ _BKMtracker.xlsx”,文件格式:= xlOpenXMLWorkbook

歸功於@MatthewD

Sub SaveDocument()
    Dim username As String
    Dim nowFormated As String
    Dim path As String
    Dim filename As String
    Dim extention As String

    username = Environ("Username") & "_" 'gets the username
    nowFormated = CStr(Format(now, "yymmdd"))  'or every format you like
    path = "D:\" 'Wherever you want to save the file
    filename = "_BKMtracker" 'or what you want
    extention = ".xlsm" 'for example (with macros, else you have to change the FileFormat too)

    ActiveWorkbook.SaveAs filename:=path & username & nowFormated & filname & extention, _
        FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM