G
Guest
I have a VBA project in Excel to build a set of worksheets, using input from a userform (and an Access db). The program checks to make sure there are not additional worksheets already in the workbook before building new ones (in order to avoid worksheet naming conflicts). If there is more than one worksheet, the user gets a message box with the option to delete the additional worksheets, or stop the program (so they could be moved to another workbook, etc.). Then a procedure (BuildForms) is called to begin building the new worksheets. Since this takes several minutes, I added a cancel button to the userform and added DoEvents statements to the BuildForms procedure.
Here is the problem: The BuildForms procedure adds a new worksheet. When the DoEvents statement runs, it triggers the messagebox indicating there are too many worksheets - creating an endless loop that never allows the worksheets to be build. I tried adding a public variable (DeleteTrigger) that would change after worksheets had been deleted once, and making that variable part of the condition to trigger the message box. That did not prevent the message box from triggering. However, if I add a watch to the DeleteTrigger variable, to see when it changes, the procedure runs as it should. Why does this happen and is there a way to prevent it, short of removing the DoEvents statements
Thanks
John B.
Here is the problem: The BuildForms procedure adds a new worksheet. When the DoEvents statement runs, it triggers the messagebox indicating there are too many worksheets - creating an endless loop that never allows the worksheets to be build. I tried adding a public variable (DeleteTrigger) that would change after worksheets had been deleted once, and making that variable part of the condition to trigger the message box. That did not prevent the message box from triggering. However, if I add a watch to the DeleteTrigger variable, to see when it changes, the procedure runs as it should. Why does this happen and is there a way to prevent it, short of removing the DoEvents statements
Thanks
John B.