我有一個VBA代碼,它強制另存爲對話框,在嘗試保存xltm時顯示默認保存類型爲xlsm。請檢查連接的代碼,並糾正我,如果代碼是不正確workbook_beforesave event not firing
Application.EnableEvents = False
Application.DisplayAlerts = False
If SaveAsUI = True Then
bInProcess = True
'The following statements shows the save as dialog box with default path
Set FileSaveName = Application.FileDialog(msoFileDialogSaveAs)
FileSaveName.InitialFileName = ThisWorkbook.Name
FileSaveName.FilterIndex = 2 'select to save with a ".xlsm" extension
FileSaveName.Title = "Save As"
intchoice = FileSaveName.Show
If intchoice = 0 Then
Else
FileSaveName.Execute
End If
Else 'Normal Save
bInProcess = True
Cancel = True
ThisWorkbook.Save
End If
Application.EnableEvents = True
Application.DisplayAlerts = True
上面的代碼工作正常,而嘗試使用(CTRL + S)保存。如果我試圖通過Excel關閉窗口選項關閉。 Excel顯示默認的另存爲彈出式窗口。如果我點擊保存爲彈出窗口的「保存」選項,則不調用workbook_beforesave事件(另存爲對話框顯示,默認數據類型已更改爲xlsm中的xls)。我不知道我犯了什麼錯誤?請幫我擺脫這個..
在此先感謝!
希望以下私人小組Workbook_BeforeClose(取消正如布爾) – Linga
感謝您即時reply.sorry你的代碼,我做的標題是錯誤的。它在workbook_beforeSave事件 – Maya
希望現在你明白了:) – Linga