PDA

View Full Version : Check if Visual Basic Editor is open



pcsparky
12-12-2009, 03:59 AM
Is there any way of checking if I have Visual Basic editor open (with code)?

The reason I ask is that I have some code in the Workbook_Activate event, which runs perfectly well when VB editor is closed.
But for some strange reason Excel crashes if it is open. If I run the code and forget that I have it open I may be able to prevent the crash with the required code before the Workbook_Activate code.

Bob Phillips
12-12-2009, 05:58 AM
I would try and work out what is causing the crash rather than trying to bypass it.

pcsparky
12-12-2009, 09:47 AM
I can't work it out as it seems to be a bug in Excel.

Attached is a completely blank wb with the exception of this code I am talking about.

See for yourself. Open a new Excel wb and then open the attached Book1 and enable the Macro. Open VBA editor.

When you activate Book1 after deactivating the other wb the userform will show. Now try closing the userform and see if you get the same problem.

lucas
12-12-2009, 10:08 AM
This seems to be directly related to this thread that you started. Why did you start a new thread with basically the same question?

I thought you moved everything to one workbook.

http://www.vbaexpress.com/forum/showthread.php?t=29606

pcsparky
12-12-2009, 10:17 AM
I did move all of the forms to one workbook. This is a different problem but I can see why it would appear similar. This appears to be an Excel bug or I just can't understand it. The code works just fine when VBA editor is closed.

lucas
12-12-2009, 10:53 AM
So under ordinary circumstances, when the code has been developed, why would the vba editor be open?

pcsparky
12-12-2009, 10:57 AM
It wouldn't. It's just while I'm working on it when I forget that I've left VBA editor open. It's no great problem if nobody knows, just trying to expand my knowledge.

lucas
12-12-2009, 11:12 AM
I don't have 2007 but when I follow your procedure the userform does not show unless the workbook you provided is active.

Bob Phillips
12-12-2009, 11:17 AM
You can just close it before you do your code,



Application.VBE.MainWindow.Visible = False


but I still think you should find the root problrm.

pcsparky
12-12-2009, 11:21 AM
Yes that's all the code does but as I said, if the VBA editor is open and cell A1 on book1 value is 1, then the userform loads when the wb is activated. When you try to close the userform Excel gives the 'Excel has encountered a problem and needs to close' message.

I don't want to take up any more of your time. Like I said it's no great problem, I just have to remember to close the editor when testing my code. Thanks anyway for your interest lucas.

Bob Phillips
12-12-2009, 12:20 PM
Check out my latest response.