PC Review


Reply
Thread Tools Rate Thread

Check if Excel Application is already open

 
 
R.W.
Guest
Posts: n/a
 
      21st Jun 2004
In one of my projects I create an Excel Workbook and add
a new Excel workbook with this code:

Set xlsObject = CreateObject("Excel.Application")
Set xlsWorkbook = xlsObject.Workbooks.Add()

But when the user previously has opened MS Excel himself,
this causes problems. So I need a methode to check if the
user has opened Excel already. If not I can use previous
code otherwise I need a way to assign the open Excel
application to the variable xlsObject.

All positive suggestions welcome, thanks

R.W.
 
Reply With Quote
 
 
 
 
Dave Jones
Guest
Posts: n/a
 
      21st Jun 2004
In the references, set a reference to Excel

Then use the following code:

On Error Resume Next
Set xlsObject = GetObject(, "Excel.Application")
Err.Clear
If xlsObject Is Nothing Then
Set xlsObject = CreateObject("Excel.Application")
End If
On Error GoTo Errorhandler
Set xlsWorkbook = xlsObject.Workbooks.Add()

This will look to find an instance of Excel and if there is one use it. If
there is not, an error is generated (hence the On Error Resume Next) and
then a new instance of Excel is created.

Dave

"R.W." <(E-Mail Removed)> wrote in message
news:1f29501c45761$83960df0$(E-Mail Removed)...
> In one of my projects I create an Excel Workbook and add
> a new Excel workbook with this code:
>
> Set xlsObject = CreateObject("Excel.Application")
> Set xlsWorkbook = xlsObject.Workbooks.Add()
>
> But when the user previously has opened MS Excel himself,
> this causes problems. So I need a methode to check if the
> user has opened Excel already. If not I can use previous
> code otherwise I need a way to assign the open Excel
> application to the variable xlsObject.
>
> All positive suggestions welcome, thanks
>
> R.W.



 
Reply With Quote
 
Jamie Collins
Guest
Posts: n/a
 
      21st Jun 2004
"R.W." wrote ...

> In one of my projects I create an Excel Workbook and add
> a new Excel workbook with this code:
>
> Set xlsObject = CreateObject("Excel.Application")
> Set xlsWorkbook = xlsObject.Workbooks.Add()
>
> But when the user previously has opened MS Excel himself,
> this causes problems. So I need a methode to check if the
> user has opened Excel already.


Try:

On Error Resume Next
Set xlsObject = GetObject(, "Excel.Application")
On Error GoTo 0
If xlsObject Is Nothing Then
Set xlsObject = CreateObject("Excel.Application")
End If

Jamie.

--
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for open Excel workbook and then close it and Excel =?Utf-8?B?UmFuZHkgV2F5bmU=?= Microsoft Access External Data 5 5th Jul 2006 02:07 PM
Can Excel open a new application every time you open a file? =?Utf-8?B?c2hvb24=?= Microsoft Excel Setup 0 13th Dec 2005 03:28 PM
Check if a file is allready open by other application Marcel Hug Microsoft C# .NET 4 20th Jan 2005 01:51 PM
Check if an application is open Warrio Microsoft Access Forms 1 12th Nov 2004 01:00 PM
Check if an application is open Warrio Microsoft Access Form Coding 1 12th Nov 2004 11:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:28 AM.