First, I know of no way to cause VBA code to run if someone opens the VBA development window. I'm not going to tell you it's impossible, but I have no idea how you could do that.
Second, it sounds like you are trying to put some sort of security on the code. Excel is notoriously weak when it comes to security. The security is generally good for compliant users but not malicious users. In your case, even if you could create code to close the workbook, the user has to simply disable macros and then your code won't run.
You may need to consider other options, like a commercial Excel compiler that will bundle your Excel file into a format where the code cannot be read.