?
Solved

Manually Opened Excel Instance Interferes with Excel OLE Automation from VB

Posted on 2007-03-26
7
Medium Priority
?
212 Views
Last Modified: 2013-11-26
Hi,

I have a problem with OLE Automation with Excel from VB 6.0 Pro.  I have several procedures that send data to Excel to create reports.  Some of them take a little while to create and the users work on other things while they are running.  If they go to My Computer / Explorer and double-click on an Excel file it will open in the instance of Excel VB opened and interfere with the report running.  This is how I declare my Excel related variables:

        Set oxl = CreateObject("Excel.application")
        Set oBook = oxl.Workbooks.add()
        Set oSheet = oBook.Sheets("Sheet1")

Is there any way to avoid this problem, other than tying the users' hands down while their reports are generating?

Thanks!
0
Comment
Question by:tlchavet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 13

Expert Comment

by:nike_golf
ID: 18794733
More than likely you'll want to use early binding vs. late binding to solve some of those issues. Take a look at this thread it has some good examples and is a great source of information.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20313838.html?sfQueryTermInfo=1+bind+earli+excel

NG,
0
 
LVL 1

Author Comment

by:tlchavet
ID: 18794846
Hi,
Sorry I should have included my dims:
    Dim oxl As Excel.Application
    Dim oBook As Excel.Workbook
    Dim oSheet As Excel.worksheet
I am using early binding.
0
 
LVL 13

Expert Comment

by:nike_golf
ID: 18795146
Try using the keyword "New"

Dim oxl As New Excel.Application

or

Set oxl = New Excel.Application

NG,
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:tlchavet
ID: 18799805
Hi,

I tried that.  The user still picks up the instance opened by VB if they double-click another Excel worksheet to open.  Is there a way to have VB open it's instance "exclusively".

Thanks
0
 
LVL 13

Accepted Solution

by:
nike_golf earned 2000 total points
ID: 18810133
Well the problem is more of an Excel problem than a coding problem.

Using the following:

Dim oXL As Object
Dim oBook As Object
Dim oSheet As Object

Private Sub Command1_Click()
Set oXL = New Excel.Application
Set oBook = oXL.Workbooks.Add()
Set oSheet = oBook.Sheets("Sheet1")
oXL.Visible = True
oXL.WindowState = xlMinimized

MsgBox "Excel Open"

Set oSheet = Nothing
Set oBook = Nothing

oXL.Quit
Set oXL = Nothing

MsgBox "Excel Closed"

End Sub


This sub does create a separate instance of Excel, the problem I see is that when you open an additional workbook after your code is running Excel uses that instance to open the workbook in. However, if you perform the operation in reverse order it keeps the instances separate, a "New" instance is created for your application.

My guess would be that Excel is using the GetObject() function by default when opening a new workbook...

NG,
0
 
LVL 1

Author Comment

by:tlchavet
ID: 18811033
Thanks - the problem then boils down to the users needing to be patient.  Thanks a bunch for the assistance!
0
 
LVL 13

Expert Comment

by:nike_golf
ID: 18811270
Sorry, I couldn't give you the answer you were looking for...

NG,
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question