|
-
Oct 8th, 2001, 02:55 AM
#1
Thread Starter
New Member
Excel as an object server - problems
help...
I am using the Excel 9 object library as part of an application I've written. I use the function below to check this is a valid Excel spreadsheet. Every time I call this, Windows starts another instance of Excel.EXE, and doesn't terminate it when I'm finished. This is a major pain. Any ideas ? (NOTE - this is the only code which uses the Excel object model at present - I'm not even doing anything yet !)
Public Function IsValidExcelFile(ByVal vstrFileName As String) As Boolean
Dim objBook As Excel.Workbook
On Error GoTo handler
IsValidExcelFile = False
Set objBook = Excel.Workbooks.Open(vstrFileName)
IsValidExcelFile = True
handler:
Set objBook = Nothing
End Function
-
Oct 8th, 2001, 08:44 AM
#2
try GetObject. I've only ever used Excel.Application, create a workbook, worksheet - total 3 objects.
GetObject will only create an instance of Excel if none is running. The way you did it was to force the creation of a new instance everytime.
Code:
' you need to experiment with GetObject
Dim objBook as Excel.Workbook
Set objBook = GetObject(vstrFileName,"")
.... check for failure
... do stuff
Excel.Workbooks.Quit ' I think it's quit, don't remember
Set objWorkBook = Nothing
-
Oct 8th, 2001, 08:55 AM
#3
Thread Starter
New Member
cheers Jim, that works a treat
I wouldn't be using the Excel object model if the ADO provider for Excel worked properly ... but hey, nothing's perfect ..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|