PritishS
Board Regular
- Joined
- Dec 29, 2015
- Messages
- 119
- Office Version
- 2007
- Platform
- Windows
Dear Sir/Madam,
Good Day!!
I'm stuck with a strange problem and can not get any solutions.
Problem: I have a macro enabled workbook say ABC.xlsm. I have code in ThisWorkbook for saving the file while closing.
and Workbook_BeforeSave event have a code to reset password of workbook, if any one try to change it.
This file is crashing in two cases--
Case 1: When I close excel file by clicking red 'X' close button.
Case 2: Wherever I used ThisWorkbook.Save code in any of my code module.
What I have tried yet:
1. I debug through any code which is causing crash using F8. I found whenever code reached to ThisWorkbook.Save, it crashes.
2. Also I have used 'DoEvents' after ThisWorkbook.Save in Workbook_BeforeClose event. But didn't work.
3. Then I had a doubt that maybe before going in ThisWorkbook.Save, code is trying to reset the password. So I commented that password line and it never crashed since.
Removed comment from Me.Password = "123" and tried 'save' and excel got crashed!!
My question:
Please guide me why this is happening??
Moreover I have other excel macro enabled files where I use this Workbook_BeforeSave and Workbook_BeforeClose combination. Each of those files are working smooth since last 2-3 years.
Kindly suggest if anyone having the same experience and solution.
Thanks & Regards,
PritishS
Good Day!!
I'm stuck with a strange problem and can not get any solutions.
Problem: I have a macro enabled workbook say ABC.xlsm. I have code in ThisWorkbook for saving the file while closing.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub
and Workbook_BeforeSave event have a code to reset password of workbook, if any one try to change it.
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Me.Password = "123"
End Sub
This file is crashing in two cases--
Case 1: When I close excel file by clicking red 'X' close button.
Case 2: Wherever I used ThisWorkbook.Save code in any of my code module.
What I have tried yet:
1. I debug through any code which is causing crash using F8. I found whenever code reached to ThisWorkbook.Save, it crashes.
2. Also I have used 'DoEvents' after ThisWorkbook.Save in Workbook_BeforeClose event. But didn't work.
3. Then I had a doubt that maybe before going in ThisWorkbook.Save, code is trying to reset the password. So I commented that password line and it never crashed since.
Removed comment from Me.Password = "123" and tried 'save' and excel got crashed!!
My question:
Please guide me why this is happening??
Moreover I have other excel macro enabled files where I use this Workbook_BeforeSave and Workbook_BeforeClose combination. Each of those files are working smooth since last 2-3 years.
Kindly suggest if anyone having the same experience and solution.
Thanks & Regards,
PritishS
Last edited: