午夜视频在线网站,日韩视频精品在线,中文字幕精品一区二区三区在线,在线播放精品,1024你懂我懂的旧版人,欧美日韩一级黄色片,一区二区三区在线观看视频

分享

Excel|如何使用VBA在工作簿文件名稱(chēng)后添加保存時(shí)間的后綴?|時(shí)間

 jeamychu 2016-05-01

 


Q:如何使用VBA在工作簿文件名稱(chēng)后添加文件保存時(shí)間的后綴,并且能不斷的隨著保存操作更新這個(gè)后綴?
A:在Thisworkbook里面加入下面的代碼即可實(shí)現(xiàn),并且能更新后綴,使得我們一眼就能看出文件的最后保存時(shí)間。
方法一 By 軒轅軾軻
  1. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  2.       On Error Resume Next
  3.       Application.DisplayAlerts = False
  4.       Fold = ThisWorkbook.FullName
  5.       Fpath = ThisWorkbook.Path
  6.       ThisWorkbook.Save
  7.       Application.DisplayAlerts = False
  8.       T = Format(Now, " YYYY年MM月DD日HH時(shí)MM分SS秒")
  9.       If Mid(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4, 1) = "秒" Then
  10.          Temp = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 25)
  11.          Else
  12.          Temp = Split(ThisWorkbook.Name, ".")(0)
  13.       End If
  14.       Fname = Fpath & "\" & Temp & T & ".xls"
  15.       ThisWorkbook.ChangeFileAccess xlReadOnly
  16.       Name Fold As Fname
  17.       Application.Workbooks.Open Fname, False
  18.       ThisWorkbook.Close False
  19.       Application.DisplayAlerts = False
  20.       Cancel = False
  21. End Sub
復(fù)制代碼


方法二 By  KevinChengCW
  1. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  2. Dim mPath$, FN$, nName$
  3. Application.ScreenUpdating = False
  4. Application.DisplayAlerts = False
  5. Application.EnableEvents = False
  6. FN = ThisWorkbook.Name
  7. mPath = ThisWorkbook.Path
  8. With ThisWorkbook
  9.     .ChangeFileAccess xlReadOnly
  10.     If InStr(FN, "-Ver") > 0 Then
  11.         .SaveAs mPath & "\" & Split(FN, "-Ver")(0) & "-Ver" & Format(Now, "yyyymmddhhmmss") & "." & Right(FN, Len(FN) - InStrRev(FN, ".")), ThisWorkbook.FileFormat
  12.     Else
  13.         .SaveAs mPath & "\" & Left(FN, InStrRev(FN, ".") - 1) & "-Ver" & Format(Now, "yyyymmddhhmmss") & "." & Right(FN, Len(FN) - InStrRev(FN, ".")), ThisWorkbook.FileFormat
  14.     End If
  15. End With
  16. Kill mPath & "\" & FN
  17. Cancel = True
  18. Application.EnableEvents = True
  19. Application.DisplayAlerts = True
  20. Application.ScreenUpdating = True
  21. End Sub
復(fù)制代碼 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多