Hi Tony,
I must admit I'm puzzled about this. My original test was with XL2000, I've
since repeated with both Xl2000 & XL2003 in different systems but with
identical Word & Excel files and get different results. Namely in XL2k the
workbook open event fires and appears to re-enable events. XP works as
expected. Full details of my test -
Book2.xls contains -
'thisWorkbook module
Private Sub Workbook_Open()
Debug.Print "Workbook_Open " & ThisWorkbook.Name
Debug.Print Application.EnableEvents
End Sub
' Normal Module
Sub auto_open()
Debug.Print "auto_open " & ThisWorkbook.Name
End Sub
In a new session of windows, with no instances of Excel, I ran the following
from Word
' Word normal module
Dim oXL As Object ' Excel.Application
Dim oWB As Object ' Excel.Workbook
Sub TestOpen()
Dim s As String
s = "C:\My Documents\Excel\Book2.xls"
Set oXL = CreateObject("Excel.application")
oXL.enableevents = False
Debug.Print oXL.enableevents ' xl2k - False, XP-False
Set oWB = oXL.Workbooks.Open(s)
Debug.Print oXL.enableevents ' xl2k - True, XP-False
oXL.Visible = True
'oXL.enableevents = True
'oWB.RunAutoMacros 1 'xlAutoOpen
End Sub
Sub TestClose()
'oWB.RunAutoMacros 2 'xlAutoClose
oWB.Close
Set oWB = Nothing
oXL.Quit
Set oXL = Nothing
End Sub
After running TestOpen I look in Excel's VBA immdeiate window and read -
xl2k -
Workbook_Open Book2.xls
True
xl-xp -
empty, ie no event fired
So despite disabling events with
oXL.enableevents = False
in xl2k the Workbook_Open has fired and reset events, indeed similar re
events is
confirmed by the two debug lines in Word, before & after opening the book.
Auto_open did not fire.
In contrast to tests before my last post, now when opening the book2.xls in
xl2k with
shift depressed disables the open events as expected.
I don't know if this difference between versions is normal or due to
something else in my xl2k system.
Regards,
Peter T