LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default calling macro from another instance of excel

That's not a bad approach, but I found it more reliable to use

Dim XLB As Excel.Workbook
Set XLB = GetObject("C:\Book1.xls")
XLB.Parent.Run "Book1.xls!AAA"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"Peter T" <peter_t@discussions wrote in message
...
Providing you know the path of the file, as well of course as it's name,
try
the following -

Sub test()
Dim sFolder As String
Dim sFile As String
Dim sMacro As String
Dim wb As Workbook
Dim xlApp As Excel.Application

sFile = "myBook.xls"
sFolder = "C:\My Documents\Excel\"

On Error Resume Next
Set xlApp = GetObject(sFolder & sFile).Parent
On Error GoTo errH

If xlApp Is Nothing Then
MsgBox sFile & " not found"
Else

sMacro = "'" & sFile & "'!" & "myMacro"
xlApp.Run sMacro

'' if you want to do stuff to the file
' Set wb = xlApp.Workbooks(sFile)
' wb.Worksheets(1).Range("A1") = Now
End If

Exit Sub
errH:
MsgBox Err.Description

End Sub

Normally this should find the file if loaded in any instance, even own
instance.
Bear in mind any dialogs or msgbox's that myMacro shows may be hidden
behind
other windows, though some API calls could bring the instance to the
front.

If you don't know the the file's path it's considerably more difficult to
reference other unknown instances.

Regards,
Peter T

"Paul" wrote in message
...
Is it possible to create a macro in one instance of excel to call/elecute
another macro in another instance of excel??

Say the first instance macro is first_instance.xls!macro1 and the second
instance macro is second_instance.xls!macro2. Both files are on the

desktop
of one machine.

The two macros are outside each other's scope, but is it possible to call
one from the other anyway???

What would the calling code line say?








 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Macro in another workbook already OPENED in another instance of Excel [email protected] Excel Programming 3 December 27th 06 04:37 AM
How do I get one instance of Excel to communicate with another instance? [email protected] Excel Programming 3 November 21st 06 10:31 PM
calling excel macro TommyBoy Excel Programming 0 August 12th 04 10:25 PM
Calling Excel Macro From Vc++ via DDE hari Excel Programming 0 July 6th 04 12:50 PM
calling a dll from excel macro Stefan[_4_] Excel Programming 1 December 12th 03 12:16 AM


All times are GMT +1. The time now is 09:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"