PC Review


Reply
Thread Tools Rate Thread

(Cross Post)

 
 
Mr.Frog.to.you@googlemail.com
Guest
Posts: n/a
 
      4th Aug 2009
Hi Everyone,

First I would like to apologize for the cross posting - I am just not
sure where the right forum is for this question. I hope that it is
here!

I have found a problem that I am hoping to find a solution for. Simply
put, when I create an Excel.Application object with late binding, set
the .EnableEvents property to False and then open a workbook,
the .EnableEvents property is 'magically' set back to true. This
problem does not exist if I use early binding. Does anyone know how /
why this is happening and /or a way to get around it.

This is a problem for me because the workbooks that I am opening have
a form set to open on the WorkBook_Open event, and this form opens
behind all other visible forms and the Excel.Application object
displays nothing of course on the taskbar. My macro code stops running
while it waits for the form to be used / closed before continuing.
This is a problem that I would like to avoid. I do not understand why
changing to late binding is producing this different set of
behaviours.

To test this yourselves, just make a blank workbook, place a blank
form (doesnt need any controls for this experiment), and have it
display with the Workbook_Open event (do leave yourself a close
button!). Open the workbook with the following code (standard Module):

Sub test()

Dim XL As Object 'Excel itself
Dim WB As Object 'Workbook
Dim WS As Object 'Worksheets Collection
Dim ss As Object 'Spreadsheet (not set, just stays as object)

On Error GoTo ErrorHandler

Set XL = CreateObject("Excel.Application")

XL.DisplayAlerts = False
XL.Application.DisplayAlerts = False
XL.Application.EnableEvents = False
XL.EnableEvents = False

Set WB = XL.Workbooks.Open(<INSERT NAME.xls OF THE WORKBOOK
FILE HERE>)

Set WS = XL.ActiveWorkbook.Sheets

For Each ss In WS
Debug.Print Filename & vbTab & vbTab & ss.Name
Next

Set WS = Nothing
WB.Close savechanges:=False

Set WS = Nothing
Set WB = Nothing
Set XL = Nothing

Exit Sub

ErrorHandler:
Debug.Print Error & vbTab & Err
Stop
Resume Next
End Sub

What you should see is that the application 'stops' running after the
Set WB = XL.Workbooks.Open line of code. It is actually still running,
just waiting for the form in the XL.Application object to be closed
before continuing. As you can see from the code above the EnableEvents
is definitely set to false, and if you watch the state of this
property in the XL.Application object you will see that it actually
changes state, all by itself, when the workbook.open method is called.
This does not happen with early binding - the EnableEvents property
stays as you put it, but it does change when using late binding and I
dont know why.

Can anyone help with this?

Excel 2000 SP3 build 9.0.8950

Cheers

The Frog
 
Reply With Quote
 
 
 
 
Sam Wilson
Guest
Posts: n/a
 
      4th Aug 2009
You could make the user form not modal -

UserForm1.Show (False)

Sam

"(E-Mail Removed)" wrote:

> Hi Everyone,
>
> First I would like to apologize for the cross posting - I am just not
> sure where the right forum is for this question. I hope that it is
> here!
>
> I have found a problem that I am hoping to find a solution for. Simply
> put, when I create an Excel.Application object with late binding, set
> the .EnableEvents property to False and then open a workbook,
> the .EnableEvents property is 'magically' set back to true. This
> problem does not exist if I use early binding. Does anyone know how /
> why this is happening and /or a way to get around it.
>
> This is a problem for me because the workbooks that I am opening have
> a form set to open on the WorkBook_Open event, and this form opens
> behind all other visible forms and the Excel.Application object
> displays nothing of course on the taskbar. My macro code stops running
> while it waits for the form to be used / closed before continuing.
> This is a problem that I would like to avoid. I do not understand why
> changing to late binding is producing this different set of
> behaviours.
>
> To test this yourselves, just make a blank workbook, place a blank
> form (doesnt need any controls for this experiment), and have it
> display with the Workbook_Open event (do leave yourself a close
> button!). Open the workbook with the following code (standard Module):
>
> Sub test()
>
> Dim XL As Object 'Excel itself
> Dim WB As Object 'Workbook
> Dim WS As Object 'Worksheets Collection
> Dim ss As Object 'Spreadsheet (not set, just stays as object)
>
> On Error GoTo ErrorHandler
>
> Set XL = CreateObject("Excel.Application")
>
> XL.DisplayAlerts = False
> XL.Application.DisplayAlerts = False
> XL.Application.EnableEvents = False
> XL.EnableEvents = False
>
> Set WB = XL.Workbooks.Open(<INSERT NAME.xls OF THE WORKBOOK
> FILE HERE>)
>
> Set WS = XL.ActiveWorkbook.Sheets
>
> For Each ss In WS
> Debug.Print Filename & vbTab & vbTab & ss.Name
> Next
>
> Set WS = Nothing
> WB.Close savechanges:=False
>
> Set WS = Nothing
> Set WB = Nothing
> Set XL = Nothing
>
> Exit Sub
>
> ErrorHandler:
> Debug.Print Error & vbTab & Err
> Stop
> Resume Next
> End Sub
>
> What you should see is that the application 'stops' running after the
> Set WB = XL.Workbooks.Open line of code. It is actually still running,
> just waiting for the form in the XL.Application object to be closed
> before continuing. As you can see from the code above the EnableEvents
> is definitely set to false, and if you watch the state of this
> property in the XL.Application object you will see that it actually
> changes state, all by itself, when the workbook.open method is called.
> This does not happen with early binding - the EnableEvents property
> stays as you put it, but it does change when using late binding and I
> dont know why.
>
> Can anyone help with this?
>
> Excel 2000 SP3 build 9.0.8950
>
> Cheers
>
> The Frog
>

 
Reply With Quote
 
Mr.Frog.to.you@googlemail.com
Guest
Posts: n/a
 
      4th Aug 2009
Sounds good, so how would I detect if a form is open, and the name of
the open form?

This still doesnt get around the issue that code runs when late
binding is used. I dont control the incoming workbooks, so I must be
careful that any startup code doesnt change the data in the sheets. I
believe that disabling events is the only way to actually achieve this
and know with certainty that the workbook is unaltered by its
activation on opening.

Still cant figure out why this is happening.

The Frog
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross post sorry from vb.net, just looking for as much help on this as possible.... =?Utf-8?B?QW50aG9ueSBOeXN0cm9t?= Microsoft Dot NET Framework Forms 0 15th Mar 2004 01:31 AM
Hi (I am not sure where to post sorry for cross post in advance) Daniel Microsoft Windows 2000 Active Directory 1 3rd Oct 2003 11:37 PM
Hi (I am not sure where to post sorry for cross post in advance) Daniel Microsoft Windows 2000 Deployment 1 3rd Oct 2003 11:37 PM
cross post wipro_testa Microsoft Access ADP SQL Server 0 29th Aug 2003 05:42 AM
cross post hello sanjay Microsoft Access ADP SQL Server 0 28th Aug 2003 06:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:02 PM.