Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I run 2 macros at the same time

465 views
Skip to first unread message

jo

unread,
Jan 28, 2003, 10:43:20 AM1/28/03
to
How can I run 2 excel macros at the same time in 2
different workbook

Chip Pearson

unread,
Jan 28, 2003, 11:07:59 AM1/28/03
to
You can't. You would have to have to separate instances of Excel
running.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com

"jo" <jerome...@bcd-microtechnique.com> wrote in message
news:0b5b01c2c6e3$fbda51a0$d4f82ecf@TK2MSFTNGXA11...

sudhendra

unread,
Jan 28, 2003, 2:18:00 PM1/28/03
to
And how can that be done!!!!!

Please tell us in detail.....

Thanks

>.
>

John Walkenbach

unread,
Jan 28, 2003, 5:10:10 PM1/28/03
to
1. Start Excel

2. Start Excel again.

That will give you two instances of Excel. You can run a macro in each one.
But, the instances won't be able to communicate with each other. In other
words, a macro in Instance #1 can't work with a workbook that's open in
Instance #2.

John Walkenbach
For Excel tips, macros, & downloads...
http://j-walk.com/ss


"sudhendra" <acli...@yahoo.com> wrote in message
news:02dd01c2c701$f9228900$d2f82ecf@TK2MSFTNGXA09...

Harlan Grove

unread,
Jan 28, 2003, 6:30:48 PM1/28/03
to
"John Walkenbach" wrote...

>1. Start Excel
>
>2. Start Excel again.
>
>That will give you two instances of Excel. You can run a macro in each one.
>But, the instances won't be able to communicate with each other. In other
>words, a macro in Instance #1 can't work with a workbook that's open in
>Instance #2.
..

Depends.

Create D:\tmp\foo.xls and D:\tmp\bar.xls. Then insert a general VBA module in
foo.xls containing


Sub foo()
Dim wkb As Object
Set wkb = GetObject("D:\tmp\bar.xls")
MsgBox _
wkb.Worksheets("Sheet1").Range("A1").Address(0, 0, xlA1, 1) & _
Chr(13) & wkb.Worksheets("Sheet1").Range("A1").Value
wkb.Worksheets("Sheet1").Range("A2").Value = "A present from " & _
ThisWorkbook.FullName
Set wkb = Nothing
End Sub


and insert a general VBA module in bar.xls containing


Sub bar()
Dim wkb As Object
Set wkb = GetObject("D:\tmp\foo.xls")
MsgBox _
wkb.Worksheets("Sheet1").Range("A1").Address(0, 0, xlA1, 1) & _
Chr(13) & wkb.Worksheets("Sheet1").Range("A1").Value
wkb.Worksheets("Sheet1").Range("A2").Value = "A present from " & _
ThisWorkbook.FullName
Set wkb = Nothing
End Sub


Now open each workbook in a separate application instance, and run their
respective macros. Seems like they can be interconnected to some extent, no? For
that matter, both instances can use wkb.Application.Run to run macros in the
other workbook in the other application instance. All that seems not be be
allowed is simultaneous 'circular' OLE client-server linking, but it's possible
to switch control back and forth using [pseudo]semaphores and

Do While CheckSemaphore : Yield : Loop

constructs in macros in both files to coordinate execution. I suppose it'd be
possible to use API calls to create less ad hoc IPC conduits, but I haven't
tried doing that sort of thing in Windows.

--
Public Service Announcement
Don't attach files to postings in nonbinary newsgroups like this one.

0 new messages