Excel automation: How to access XL sheet as the second task?
One workbook is opened by the user (independently of my app), second one is
opened by my app.
Jack
"Tim Williams" <timjwilliams at gmail dot com wrote in message
...
You can't have the same workbook open in two different instances of Excel.
Tim
"Jack" <replyto@it wrote in message
...
Hello,
I have a technical problem how to read from XL sheet in the
second task.
Let assume there is Excel spreadsheet already opened on desktop.
My code:
Public WithEvents moExcelApp As Excel.Application
Public WithEvents moExcel2ndTask As Excel.Application
Set moExcelApp = GetObject(, "Excel.Application")
If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application")
End If
If moExcelApp Is Nothing Then
Debug.Print "Excel app NOT found!"
ExcelApp = 1: Exit Sub
Else
moExcelApp.EnableEvents = True
Set moExcel2ndTask = CreateObject("Excel.Application")
moExcel2ndTask.EnableEvents = True
End If
==================
In Task Manager I can see the second Excel task running.
But it is not bound to the spreadsheet already opened, like moExcelApp
is.
For example:
moExcel2ndTask.Workbooks.Count returns 0
but
moExcelApp.Workbooks.Count returns 1.
What should be done to bind the second Excel task to the already opened
spreadsheet?
What am I doing wrong?
What I need is to be able to read the cell values in the Excel second
task, while not to disturb user using the sheet in primary task (just to
avoid errors while sheet is in edit mode).
Your thoughts appreciated,
Jack
|