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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instantiated Excel object is closed by user - VB still works

Status
Not open for further replies.

PaulAH

Programmer
Oct 29, 2002
26
NZ
I have an app (VB6) which instantiates Excell and creates/displays a workbook to the user via a button.

The problem I have is if the user closes Excell the app still works (i.e. the user can recreate a workbook using the button) but any subsequent workbooks created are not visible. The Excell.exe process is still active (viewed via task manager) and the application doesn't crash.
How can I get as newly created workbook to display?

Here's my code for opening/displaying a workbook...

[blue]
Public Function OpenWorkBook(strWorkBook As String) As Excel.Workbook

On Error GoTo err_OpenWorkBook

If XcellApp Is Nothing Then
Set XcellApp = New Excel.Application
Else
If XcellApp.Visible = False Then XcellApp.Visible = True
End If

'This closes any open workbook of this name..
On Error Resume Next
Workbooks(strWorkBook).Close SaveChanges:=False

On Error GoTo err_OpenWorkBook
Set OpenWorkBook = XcellApp.Workbooks.Open(App.Path + "\Templates\" + strWorkBook, , True)
XcellApp.Visible = True

Exit Function

err_OpenWorkBook:

MsgBox ("An error has occurred in S/R OpenWorkBokk " _
+ Chr(13) + "Error Number = " + CStr(Err.Number) _
+ Chr(13) + "Error Description = " + Err.Description)

End Function
[/blue]

Any help would be appreciated.....cheers
 
Hi PaulAH

I had a similar situation where my excel did not want to open for a second time, and you have to restart before it opens again.

I later found that this happened once there was an error in my code, and the Excell object could not be successfully "used/created", I had to restart before it worked again.

I had an XLS file to which I wrote as a recordset (database). If I tried to create a new Excell document from my code, and the last XLS file was still there, excell didn't open properly. Thus, now, before I write to the file, I make sure I delete the last one I created.

This offcourse only has effect if you keep using the same filename for the output.

Hope this might help shed some light on your problem

*****************************************
May the Code Be With You...[lightsaber]
----------
x50-8 (X Fifty Eigt)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top