PDA

View Full Version : Basic question about Application.enableevents



neeeel
02-10-2011, 11:13 AM
Say you have 2 workbooks open, does using Application.enableevents = false in one workbook stop events in the other workbook?

Kenneth Hobs
02-10-2011, 01:13 PM
Yes, because Application is the object for that Property, not Workbook.

neeeel
02-10-2011, 01:18 PM
thats what i thought, how would i do it for single workbook, without affecting another workbook, workbook.enableevents = true?

Kenneth Hobs
02-10-2011, 01:25 PM
Most people disable, do their thing, and then enable. If you have a need for switching workbooks while code is running, then look at ThisWorkbook object and the Activate Event for those or the Deactivate event as applicable.

neeeel
02-10-2011, 01:37 PM
no, im not talking about switching workbooks, Im talking about having 2 separate workbooks, each running their own code.

mikerickson
02-10-2011, 02:11 PM
You could put Public myEventsDisabled as Boolean at the top of Workbook1's ThisWorkbook codemodule, have Workbook1's events test for that variable and act appropriatly.

You can refer to it from other workbooks with syntax like MsgBox Workbooks("Workbook1.xls").myEventsDisabled.

But, unless you are running two instances of Excel, "2 separate workbooks, each running their own code" happens only if the codes are not running at the same time.

neeeel
02-10-2011, 02:30 PM
thats what i wondered, because i have been running 2 workbooks, and they seemed to interfere with each other. how would I run 2 instances of Excel?

mikerickson
02-10-2011, 04:21 PM
I don't know how to run two instances of Excel (Mac doesn't work that way). But from what I've seen on this board from Windows users, its seldom a good idea. For one thing, a workbook that is open in one instance but not in the other is not in the other VB project's Workbooks collection.

Kenneth Hobs
02-10-2011, 04:37 PM
Two instances are most always a bad idea as Mike said. This usually happens when the programmer did not check or an active instance. If you want to do it, I could work up an example to do it probably.

neeeel
02-11-2011, 04:54 PM
I want to be able to run 2 separate workbooks, that do 2 totally different things, at the same time without them interfering with each other when I need to disable application.enableevents on 1 sheet. So even if 1 workbook is the active book, the other one will still be running code and reacting to what is happening on the other sheet, as both sheets are being updated by outside programs. I guess the easiest way would be to combine both workbooks into 1 workbook with 2 sheets, and deal with the concurrent programming problems in 1 book?