Hi there,
I personally would not use Workbook_Open or _Close for this. Rather, use the workbook's activate and deactivate events. These run upon opening/closing anyways, and additionally, catch when the user flips between workbooks in the same instance.
A quick example:
In a Standard Module:
<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br> <br><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Function</SPAN> ActivateKey()<br> Application.OnKey "B", "Sheet2.CommandButton1_Click"<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN><br> <br><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Function</SPAN> DeactivateKey()<br> Application.OnKey "B"<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN></FONT>
In the Worksheet's Module:
<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br> <br><SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()<br> Application.Goto Sheet1.Range("A10"), <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br> <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Activate()<br> <SPAN style="color:#00007F">Call</SPAN> ActivateKey<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br> <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Deactivate()<br> <SPAN style="color:#00007F">Call</SPAN> DeactivateKey<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
In ThisWorkbook Module:
<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br> <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Activate()<br> <br> <SPAN style="color:#00007F">If</SPAN> TypeName(ActiveSheet) = "Worksheet" <SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">If</SPAN> ActiveSheet.CodeName = "Sheet2" <SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Call</SPAN> ActivateKey<br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br> <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Deactivate()<br> <SPAN style="color:#00007F">Call</SPAN> DeactivateKey<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
Hope that helps,
Mark