View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
[email protected] KenCowen@cox.net is offline
external usenet poster
 
Posts: 14
Default closing another file by code causes failure to run workbookactivate event

On Tuesday, July 10, 2012 9:03:42 AM UTC-4, James Ravenswood wrote:
Post your userform code.


James

I have workbook test1.xlsm with a single userform. The userform has a single button with the following code:

Private Sub CommandButton1_Click()
Workbooks.Open ("test2.xlsm")
Unload Me

End Sub

Workbook text2.xlsm has a worksheet button with the following code:

Private Sub CommandButton1_Click()
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

WB test1.xlsm has the following in ThisWorkbook code module:

Private Sub Workbook_Activate()
UserForm1.Show
End Sub

The userform is shown whenever test1 is activated; unless test1 is activated by closing test2 through the command button1 code. If test2 is closed with the x button or file close, the userform is shown. I have workaround that is working okay, but, it seems overly complex. I have added the triggering of an OnTime code to the command button code on test2. The OnTime function triggers the redisplay of the original userform after a one second delay. It works, but, I would reall like to know why test1 does not run the activate code when it becomes active through the closing of test2.

Thanks

Ken