How do I access a variable from another instance of excel?
When you start newExcel, are you opening an existing workbook that has the
code module that contains "CodeStuff()"? How is CodeStuff() run; i.e. is it
an event procedure or is it triggered by user intervention (e.g.
commandbutton), or are you calling it from code?
Where I am going with this:
Is it possible to move CodeStuff() to your original (controlling)
application's code module instead of a module within the automated newExcel
app? Unless it is an Event Procedure, I don't see why you could not move the
code within your original calling procedure. You can use the same code as
long as you qualify all your references back to the Application by using
newExcel; e.g. NewExcel.Workbooks(1).ActiveSheet....
That way you could directly change the statusbar text within CodeStuff():
Sub CodeStuffAsPartOfOriginalStuff()
Rem Do what you would have done before starting up newExcel
Rem Then start up newExcel
Rem newExcel.Dostuff
Application.StatusBar = 1
Rem newExcel.Do more stuff
Application.StatusBar = 2
Rem Blah Blah
End Sub
If, however, CodeStuff needs to respond to events in newExcel, it is a bit
tougher. I don't know how to access a variable - even a global variable -
from an automated session (or if it is even possible). You might need to
define newExcel through a new Class module declared "With Events": In that
case you could even make ProgressCounter a property of the class... I suppose
this could work but would take a lot of coding.
"Alan" wrote:
Hi All,
I have the following situation (simplified for this posting):
I have created a new instance of excel which is performing some
actions
that take a few minutes. I would like to have a variable (just an
integer or string perhaps - doesn't really matter which) that is
updated in that instance that I can then access from the first
application object to give the user progress information.
Example:
In the main application:
NewExcel is an Excel.application object (new)
I would like to be able to do something like this:
Application.Statusbar = NewExcel.ProgressCounter
Within the NewExcel Application:
Sub CodeStuff()
Dim ProgressCounter as Integer
Rem Start of code
Rem Do stuff
ProgressCounter = 1
Rem Do more stuff
ProgressCounter = 2
Rem Blah Blah
End Sub
Within the main application, the statusbar would be showing 1, 2, 3
etc as the NewExcel application make progress.
However, I cannot work out how to access the value of ProgressCounter
from within the main excel application - any ideas?
Hope that makes sense!
Thanks,
Alan.
|