jasonb75
Well-known Member
- Joined
- Dec 30, 2008
- Messages
- 15,509
- Office Version
- 365
- Platform
- Windows
Hi all,
Below is a trimmed down version of the code that I'm attempting to use, the code executes fine when attempting to save using Ctrl s up to the point of hitting the save button on the file dialog pop up. At this point the pop up closes and nothing happens, no file is saved.
Using save as from the file menu, the code runs and saves correctly so I'm guessing that the FileDialogSaveAs pop up is not the same.
Adding a break point to the code and stepping through manually, the code ends after clicking the save button on the pop up.
I tried with and without EnableEvents = False thinking that the code could be looping and cancelling itself but this made no difference either way.
Am I missing something simple, or going about it the wrong way?
Thanks in advance for any suggestions.
Below is a trimmed down version of the code that I'm attempting to use, the code executes fine when attempting to save using Ctrl s up to the point of hitting the save button on the file dialog pop up. At this point the pop up closes and nothing happens, no file is saved.
Using save as from the file menu, the code runs and saves correctly so I'm guessing that the FileDialogSaveAs pop up is not the same.
Adding a break point to the code and stepping through manually, the code ends after clicking the save button on the pop up.
I tried with and without EnableEvents = False thinking that the code could be looping and cancelling itself but this made no difference either way.
Code:
Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If ThisWorkbook.Name = "original.xlsm" Then
' do other stuff
If SaveAsUI = False Then
Cancel = True
With Application.FileDialog(msoFileDialogSaveAs)
.InitialFileName = ThisWorkbook.Path & "\" & "Newname.xlsx"
.Show
End With
End If
End If
End Sub
Thanks in advance for any suggestions.