Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB launches Excel then interesting problem...

Status
Not open for further replies.

PaulAH

Programmer
Oct 29, 2002
26
0
0
NZ
Using a VB app I launch Excel + populate/display a workbook. All works fine if the user closes the workbook then displays another workbook (from witin the VB app)..BUT if the the user closes the Excel application, subsequent workbooks are not visible (although the frame of excel is visible and the application merrily carries on populating the workbook).
I use the Workbook_BeforeClose method to stop some specific workbooks being closed but I want the user to be able to close others so I can't block closing the last workbook in the collection all the time. Is there someway i can identify when the application close button has been pressed rather than the workbook close button?
I'm using VB6 with Excel 2000.
 
I wonder if you can use something like this to stop the last workbook being closed. Need to add a bit more to make sure you can close it when you want to :-
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If Workbooks.Count = 1 Then
        MsgBox ("Cannot close last workbook yet.")
        Cancel = True
    End If
End Sub


Regards
BrianB
Use CupOfCoffee to speed up all windows applications.
It is easy until you know how.
================================
 
Paul Ah,

Could you please post the code you are using to do that because I think launching excel with vb code would solve my enable macro problem.

I don't understand where you store the vb code after it is written. Do you write it in a workbook or where do you write/store it? Thank you in advance.
 
Hi Brian, thanks for your response. Unfortunately what you suggest is'nt any good for this app as some of the workbooks the user's have open need to have the ability to be closed. If only one of these is open then it wouldn't allow the workbook to close. Is there no way of stoppping the application from closing even though no workbooks are open?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top