Hi,
I disabled the save function on a workbook in order to prevent users from the saving the file outside a specific directory.
My only problem is that after doing that I have noticed that file takes a lot longer to save, and that a save window pops up with a progress bar. In some cases this bar pops up after the file has actually saved.
This is my code, if anyone can see any errors please let me know -
I disabled the save function on a workbook in order to prevent users from the saving the file outside a specific directory.
My only problem is that after doing that I have noticed that file takes a lot longer to save, and that a save window pops up with a progress bar. In some cases this bar pops up after the file has actually saved.
This is my code, if anyone can see any errors please let me know -
Code:
[SIZE=3][FONT=Calibri]Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Dim OutApp As Object<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Dim OutMail As Object<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Dim hlink As Hyperlink '?<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Dim strPath As String<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] A = MsgBox("Do you really want to save the workbook?", vbYesNo)<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] If A = vbNo Then<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Cancel = True<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Else<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '// Get the save path from the user<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] strPath = Application.GetSaveAsFilename(FileFilter:="Excel Files,*.xls,All Files,*.*", _<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Title:="Save As File Name")<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '// Check they didnt press cancel<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] If strPath = "False" Then<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Cancel = True<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Else<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '// Check drive letter is G<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] If Left(strPath, 28) = "G:\Commercial Services Group" Then<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '// Disable events and try to save<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Application.EnableEvents = False<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ActiveWorkbook.SaveAs Filename:=strPath<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Application.EnableEvents = True<o:p></o:p>[/FONT][/SIZE]
<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>
[SIZE=3][FONT=Calibri] Else<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] MsgBox "You are receiving this error message because you tried to save this file outside of the G:\Tendering directory, please try again and this time save your file in G:\Tendering", vbExclamation, "File Not Saved!"<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Cancel = True<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End If<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End If<o:p></o:p>[/FONT][/SIZE]
<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>
[SIZE=3][FONT=Calibri] End If<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] With Application<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] .ScreenUpdating = True<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] .EnableEvents = True<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] On Error GoTo 0<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End With<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '---------<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Cancel = True<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End Sub<o:p></o:p>[/FONT][/SIZE]