- 帖子
- 109
- 主題
- 1
- 精華
- 0
- 積分
- 116
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 2007
- 閱讀權限
- 20
- 註冊時間
- 2016-8-4
- 最後登錄
- 2018-10-22
 
|
17#
發表於 2016-11-3 09:24
| 只看該作者
回復 16# msmplay
改了一下,應該可以,再試試看。- Private Sub Workbook_BeforeClose(Cancel As Boolean)
- Dim mypath As String, fname As String
-
- fname = "\自動備份" & Format(Date, "yymmdd") & ".xlsx"
- mypath = Left(ThisWorkbook.Path, InStrRev(ThisWorkbook.Path, "\") - 1)
- Targetfile = mypath & fname
-
- If Not Me.Saved Then
- Msg = "Do you want to save the changes you made to "
- Msg = Msg & Me.Name & "?"
- Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
- Select Case Ans
- Case vbYes
- Me.Save
- Case vbNo
- Me.Saved = False
- Case vbCancel
- Cancel = True
- Exit Sub
- End Select
- End If
-
- If Me.Saved Then
- Application.DisplayAlerts = False '關閉系統警告訊息
- 'ThisWorkbook.Save '要儲存自身檔案,請自行選擇要不要儲存
- If Dir(Targetfile) <> "" Then
- If GetAttr(Targetfile) And vbReadOnly Then
- SetAttr Targetfile, vbNormal
- End If
- End If
- ThisWorkbook.SaveAs mypath & fname, FileFormat:=xlOpenXMLWorkbook
- Application.DisplayAlerts = True '開啟系統警告訊息
- Else
- Me.Saved = True
- End If
- If Dir(Targetfile) <> "" Then
- If GetAttr(Targetfile) Then
- SetAttr Targetfile, vbReadOnly
- End If
- End If
-
- End Sub
複製代碼 |
|