Hi all,

I am attempting to create a macro in that when an email is received with a certain subject it runs a macro through a rule.

The spreadsheet will be open all the time in the background.

I have created a macro however when it runs it reopens the file and runs the macro but I want it to run it in the file that is already open.

The current code is:

Sub Management_Accounts(item As Outlook.MailItem)

Dim objExcel As Excel.Application
Set objExcel = New Excel.Application

objExcel.Visible = True

If IsWorkBookOpen("K:\file.xlsm") Then

Else

objExcel.Workbooks.Open "K:\file.xlsm"

End If

objExcel.Run "Refresh_Single"

Set objExcel = Nothing

End Sub

Function IsWorkBookOpen(FileName As String)
Dim ff As Long, ErrNo As Long

On Error Resume Next
ff = FreeFile()
Open FileName For Input Lock Read As #ff
Close ff
ErrNo = Err
On Error GoTo 0

Select Case ErrNo
Case 0: IsWorkBookOpen = False
Case 70: IsWorkBookOpen = True
Case Else: Error ErrNo
End Select
End Function
Any help would be greatly appreciated, as you can see I have attempted to create a function already.

Thanks in advance