X
XP
Using Office 2003 and Windows XP;
I am trying to trap the Workbook_BeforeClose event so that I can substitute
a call to my own save function, see below:
Public Function FileSavePrompt(argPath As String, argName As String) As Long
'SUPPLY A DEFAULT FILE NAME AND PROMPT THE USER TO SAVE THE FILE;
Application.ScreenUpdating = True
Dim lResponse As Long
With Application.FileDialog(msoFileDialogSaveAs)
.AllowMultiSelect = False
.ButtonName = "SAVE!"
.InitialView = msoFileDialogViewDetails
.InitialFileName = argPath & argName
.Title = "SAVE FILE AS EXCEL"
End With
lResponse = Application.FileDialog(msoFileDialogSaveAs).Show
'Save the file if user did not click 'Cancel'
If lResponse = -1 Then Application.FileDialog(msoFileDialogSaveAs).Execute
End Function
This function allows me to capture and enter a custom suggested file name
for the user. However, I cannot get this to function correctly. In many
cases, it errors so badly, I get the: "Do you want to send this error to
Microsoft" message.
Can someone tell me how to invoke this correctly? I've tried all
combinations of Cancel = True and Application.EnableEvents = False, but I
must not be putting my code in the right place or something. Any help
appreciated.
Thanks much in advance.
I am trying to trap the Workbook_BeforeClose event so that I can substitute
a call to my own save function, see below:
Public Function FileSavePrompt(argPath As String, argName As String) As Long
'SUPPLY A DEFAULT FILE NAME AND PROMPT THE USER TO SAVE THE FILE;
Application.ScreenUpdating = True
Dim lResponse As Long
With Application.FileDialog(msoFileDialogSaveAs)
.AllowMultiSelect = False
.ButtonName = "SAVE!"
.InitialView = msoFileDialogViewDetails
.InitialFileName = argPath & argName
.Title = "SAVE FILE AS EXCEL"
End With
lResponse = Application.FileDialog(msoFileDialogSaveAs).Show
'Save the file if user did not click 'Cancel'
If lResponse = -1 Then Application.FileDialog(msoFileDialogSaveAs).Execute
End Function
This function allows me to capture and enter a custom suggested file name
for the user. However, I cannot get this to function correctly. In many
cases, it errors so badly, I get the: "Do you want to send this error to
Microsoft" message.
Can someone tell me how to invoke this correctly? I've tried all
combinations of Cancel = True and Application.EnableEvents = False, but I
must not be putting my code in the right place or something. Any help
appreciated.
Thanks much in advance.