Hi
Im experiencing a very strange bug in a VBA project im maintaining.
The workbook contains a list of testusers and the properties they have. The VBA is there to hide or show the password for each of the testusers depending on the person viewing.
In order to make sure that the passwords are always hidden as default (incase some user who isnt supposed to view the passwords has macroes disabled), there are some code in place to handle the BeforeSave and Open events.
The open event handler initializes some global variables, shows the passwords the person is allow to see and then sets ThisWorkbook.saved = True.
This way, if the person closes the workbook after they find a suitable testuser without making any changes, they wont see a dialog asking them to save their changes, and as a result hitting the x wont save the workbook with the passwords shown.
The BeforeSave method code is as follows:
Which from what I've gathered from various forums posts is the common way to do thing before and after the save occurs. (Hide passwords in the saved version, but then show them again).
The problem im having is that sometimes when a user makes a change to the workbook and hits the X to close, and then clicks yes to the dialog, the dialog keeps reappearing everytime they hit yes.
The really strange part is, that I've only been able to reproduce this bug when I have a second, totally unrelated, workbook open (can be empty, it doesn't matter). In this case the bug is very consistent.
Can the other workbook somehow effect the VBA code in this project?
If so how can I protect against it?
I thank you in advance for helping me
Kind regards
Troels
Im experiencing a very strange bug in a VBA project im maintaining.
The workbook contains a list of testusers and the properties they have. The VBA is there to hide or show the password for each of the testusers depending on the person viewing.
In order to make sure that the passwords are always hidden as default (incase some user who isnt supposed to view the passwords has macroes disabled), there are some code in place to handle the BeforeSave and Open events.
The open event handler initializes some global variables, shows the passwords the person is allow to see and then sets ThisWorkbook.saved = True.
This way, if the person closes the workbook after they find a suitable testuser without making any changes, they wont see a dialog asking them to save their changes, and as a result hitting the x wont save the workbook with the passwords shown.
The BeforeSave method code is as follows:
Code:
Application.EnableEvents = False
Application.ScreenUpdating = False
Call viewPasswords(False)
ThisWorkbook.Save
Call viewPasswords(True)
ThisWorkbook.saved = True
Application.ScreenUpdating = True
Application.EnableEvents = True
Cancel = True
Which from what I've gathered from various forums posts is the common way to do thing before and after the save occurs. (Hide passwords in the saved version, but then show them again).
The problem im having is that sometimes when a user makes a change to the workbook and hits the X to close, and then clicks yes to the dialog, the dialog keeps reappearing everytime they hit yes.
The really strange part is, that I've only been able to reproduce this bug when I have a second, totally unrelated, workbook open (can be empty, it doesn't matter). In this case the bug is very consistent.
Can the other workbook somehow effect the VBA code in this project?
If so how can I protect against it?
I thank you in advance for helping me
Kind regards
Troels