Disable Events not preventing crash....

paipimenta

Board Regular
Joined
Apr 7, 2010
Messages
103
This was offered as a solution to another's post...
http://www.mrexcel.com/forum/showthread.php?t=465898
but I got a bug in it. I've got the following code to save a copy of the current file to another location...
(To test this out, I used my Desktop[shared] and My Documents[master] as the two locations)
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If ActiveWorkbook.FullName = "S:\SharedPath\SharedWBook.xls" Then
        Application.EnableEvents = False
        Dim originalFilename As String
        originalFilename = "S:\SharedPath\SharedWBook.xls"
 
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs ("D:\MasterPath\MasterWBook.xls")
        ActiveWorkbook.SaveAs (originalFilename)
        Application.DisplayAlerts = True
 
        Application.EnableEvents = True
 
    End If
End Sub

Users operate in a shared workbook and when they save, it also saves to a master, non-shared wbook in a separate location. Using 2003, I'm getting an Excel crash 80%-90% of the time. I thought disabling events would fix it, but it hasn't. Help?
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Rather than saving it twice, I think you'd be best off using SaveCopyAs method:

Code:
ActiveWorkbook.SaveCopyAs "D:\MasterPath\MasterWBook.xls"

That way you won't need to resave it as its original filename.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top