gpt4 book ai didi

vba - 另存为按钮,无需确认

转载 作者:行者123 更新时间:2023-12-04 21:04:07 25 4
gpt4 key购买 nike

嘿,我正在尝试制作的“另存为”按钮有问题。它应该始终以相同的名称保存在相同的路径下,并且无需确认。这是我到目前为止的代码:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = False

Dim vFile
Dim strDirectoryPath As String
If SaveAsUI Then
vFile = Application.GetSaveAsFilename("C:\temp\Sample.xlsm", "Excel files (*.xlsm),*.xlsm")
If TypeName(vFile) = "Boolean" Then
Cancel = True
Application.EnableEvents = True
Exit Sub ' user cancelled
End If
strDirectoryPath = "C:\temp\"
If Dir(strDirectoryPath, vbDirectory) = "" Then MkDir strDirectoryPath

ActiveWorkbook.SaveAs vFile, FileFormat:=56
Application.EnableEvents = True
saveProcessStarted = False
Cancel = True
Exit Sub
End If
Application.EnableEvents = True
End Sub

最佳答案

我猜您在保存工作簿时不想看到任何对话框。

尝试使用以下代码:

Application.DisplayAlerts = False 
ActiveWorkbook.SaveAs vFile, FileFormat:=56
Application.DisplayAlerts = True

关于vba - 另存为按钮,无需确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28685323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com