How do I avoid multiple instances of Excel

Hi

We're running Office Professional 2003. I've written a quotation system in VBA with an Excel user interface. Each quotation is a separate workbook. The pricing information is also in other workbooks.

The application creates its own commandbar that enables users to easily transfer data from the pricing workbooks to the quotation workbooks.

All this works fine as long as all the workbooks are under one instance of Excel. However, the quotation system may either be initiated from a workbook or a word document. If the quotation system is already running and a user tries to start it again from Excel then I'm able to detect this, but if they try to start it from Word then I can't and we end up with a second instance of Excel.

The code to start the system in the Word document is very similar to that in the workbook, which in summary is ..

Dim xla as Excel.Application

Set xla = Excel.Application

This appears to work as Set xla = New Excel.Application in Word.

Any thoughts or suggestions

Thanks

PeterMo.



Answer this question

How do I avoid multiple instances of Excel

  • MCaradec

    Have a look at the GetObject Function. In the VBA help there is an example of using it to detect if Excel is running.

  • TomTogg

    Hi

    Isn't it funny how you can misunderstand things when you rush through the documentation. I had assumed (wrongly) that since Set ... = New ... (usually) created a new instance then Set ... = ... didn't.

    Thanks for your help.

    Peter Mo.


  • How do I avoid multiple instances of Excel