run macro from anoter Excel session

  • Thread starter Thread starter Dan
  • Start date Start date
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
 
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
 
Back
Top