run macro from anoter Excel session

D

Dan

Hi,
I am trying to run a macro from another open workbook on another excel
session.
I have tried using
Application.Run (PathToFile & "\" & NameOfFile & "!MacroName")
but the it open a new workbook (read only) and also get stuck.

Any idea,
Thanks
Dan
 
P

Peter T

Sub test2()
Dim PathToFile As String, NameOfFile As String
Dim XLother As Application

PathToFile = "C:\Temp"
NameOfFile = "myFile.xls"

On Error Resume Next
Set XLother = GetObject(PathToFile & "\" & NameOfFile).Parent
On Error GoTo 0

If XLother Is Nothing Then
MsgBox NameOfFile & " not found"
Else
XLother.Run "myMacro"
End If
End Sub

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top