hi,
I have the following code in the Workbook Before Save function (in This Workbook). However, it does not seem to be executing.... ANyone know why? If I put it in a macro and run it, it works. But I need it to execute when a user saves the workbook (well, after they save).
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On Error GoTo Err_WkBk
Cancel = True
Application.EnableEvents = False
ActiveWorkbook.Save
Application.EnableEvents = True
Dim tPath As String
tPath = "C:"
If ThisWorkbook.MultiUserEditing Then
Application.DisplayAlerts = False
fil = tPath & "\" & ThisWorkbook.Name
ThisWorkbook.SaveAs fil, , , , , , xlExclusive
Application.DisplayAlerts = True
Else
Application.DisplayAlerts = False
fil = tPath & "\" & ThisWorkbook.Name
ThisWorkbook.SaveAs fil, , , , , , xlShared
Application.DisplayAlerts = True
End If
Exit_Err_wkBk:
Exit Sub
Err_WkBk:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume Exit_Err_wkBk
End Sub
Thanks so much,
J
I have the following code in the Workbook Before Save function (in This Workbook). However, it does not seem to be executing.... ANyone know why? If I put it in a macro and run it, it works. But I need it to execute when a user saves the workbook (well, after they save).
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On Error GoTo Err_WkBk
Cancel = True
Application.EnableEvents = False
ActiveWorkbook.Save
Application.EnableEvents = True
Dim tPath As String
tPath = "C:"
If ThisWorkbook.MultiUserEditing Then
Application.DisplayAlerts = False
fil = tPath & "\" & ThisWorkbook.Name
ThisWorkbook.SaveAs fil, , , , , , xlExclusive
Application.DisplayAlerts = True
Else
Application.DisplayAlerts = False
fil = tPath & "\" & ThisWorkbook.Name
ThisWorkbook.SaveAs fil, , , , , , xlShared
Application.DisplayAlerts = True
End If
Exit_Err_wkBk:
Exit Sub
Err_WkBk:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume Exit_Err_wkBk
End Sub
Thanks so much,
J