excel 2010 Workbook_BeforeSave中弹出另存为窗口后保存不了
我在excel 2010中写了如下的代码,为了点击save后弹出save as对话框,并且命名文件.
但是发现点了弹出框的save后并没有保存,为什么?
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Name As String
With ThisWorkbook
Name = Worksheets("Sheet1").Range("B7").Value
Dim dlgSaveAs As FileDialog
'Set the dialog type
Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
With dlgSaveAs
.InitialFileName = Name
.FilterIndex = 2
'Display the dialog
.Show
End With
End With
End Sub
Dim Name As String
With ThisWorkbook
Name = Worksheets("Sheet1").Range("B7").Value
Dim dlgSaveAs As FileDialog
'Set the dialog type
Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
With dlgSaveAs
.InitialFileName = Name
.FilterIndex = 2
'Display the dialog
.Show
End With
End With
Sub b()
Dim Name As String
With ThisWorkbook
Name = Worksheets("Sheet1").Range("B7").Value
Dim dlgSaveAs As FileDialog
'Set the dialog type
Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
With dlgSaveAs
.InitialFileName = Name
.FilterIndex = 2
'Display the dialog
.Show
.Execute
End With
End With
End Sub