Results 1 to 3 of 3

Thread: Excel as an object server - problems

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    Swindon, UK
    Posts
    11

    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

  2. #2
    jim mcnamara
    Guest
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    Swindon, UK
    Posts
    11
    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
  •  



Click Here to Expand Forum to Full Width