Good Morning all,

I've come begging for help,

I have a number of outlook scripts which run on incoming emails which meet a set criteria... these seem to run perfect throughout the day, however occasionally when im out of the office at night some seem to fail...
I dont have admin rights however i do have elevated privledges allowing me to ensure the hard-drive isnt turning off and the computer isnt going to sleep...

I imagine its a problem with the way I have written the script... I would be very appreciative if someone could give me some pointers as to where I have gone wrong... its driving me nuts, because when every time i test the code it works fine...


This one one of the Scripts failing, I have another one which is failing too...

This one runs off a rule which checks emails as they arrive for a specific subject... it then downloads that emails attachment to C:\Temp ( i believe its failing here as there are no files in C:\temp when I check in the morning), checks if it has all the attachments required to execute the code if not it ends sub... once it has all 4 attachments in the temp folder it, opens an excel workbook and runs a macro in there (this is a pretty beefy macro which creates several reports & emails several distro lists)... It then writes a success or fail to a notepad


Dim Garb As Variant
Dim Sucfail As Variant

------------------------
Sub MailhandlerPerStatYester(ThisMail As MailItem)
    Dim wbook As Workbook
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    On Error GoTo Ender
    Garb = "Outlook Kickoff Yesterdays Stats"
    saveFolder = "C:\Temp"
    For Each objAtt In ThisMail.Attachments
    
    objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
    
    Next
    
If Dir("C:\Temp\Extract 1.xls") <> "" Then
Else
GoTo Endit
Exit Sub
End If
If Dir("C:\Temp\Extract 2.xls") <> "" Then
Else
GoTo Endit
Exit Sub
End If
If Dir("C:\Temp\Extract 3.xls") <> "" Then
Else
GoTo Endit
Exit Sub
End If
If Dir("C:\Temp\Extract 4.xls") <> "" Then
Else
GoTo Endit
Exit Sub
End If
    
    

Call OpenMacroBook

    Excel.Run ("PSY_Auto")
    Windows("MacroBook.xlsm").Close False
    Excel.Application.Quit
    Set objAtt = Nothing
    Sucfail = "Completed Successfully"
    Call WriteLog
Exit Sub
Ender:
Sucfail = "Failed to Run"
Call WriteLog
Endit:
Set objAtt = Nothing
End Sub

--------------------------
Sub OpenMacroBook()

    Set wbook = Nothing
    On Error Resume Next
    Set wbook = Excel.Workbooks("MacroBook.xlsm")
    If wbook Is Nothing Then Excel.Workbooks.Open ("\\**-***-***\***_***_*** *** ***\***** Databases\Tools\MacroBook.xlsm")
    Excel.Application.Visible = True
    Excel.Windows("MacroBook.xlsm").Activate

End Sub

-------------------------------------------
Sub WriteLog()
Dim Log As Variant

User = Environ$("Username")

Log = "\\**-***-***\***_***_*** *** ***\***** Databases\Automation Log\Log.txt"
fnum = FreeFile()

Open Log For Append As fnum
Write #fnum, Now() & " " & Garb & " " & Sucfail & " - By " & User
Close #fnum
Sucfail = Null
Garb = Null
End Sub
Many Thanks
Shakey