Hi all,
I'm trying to write a piece of code that sends a file out via outlook daily, then misses saturday and sunday, and starts again on the monday. Can someone tell me why this isn't working, the code is commented:
Sub evalDay()
If WeekDay(Now) <> 7 Or WeekDay(Now) <> 1 Then
'***** If it isn't saturday or sunday^
Application.OnTime Now + TimeValue("23:59:59"), "sendMenu.xls!Sheet1.sendIt"
'***** Wait 24 hours and call the sendIt routine^
ElseIf WeekDay(Now) = 7 Then
'***** If its Saturday^
Set oApp = CreateObject("outlook.application")
'***** Create an Outlook application object^
Set oItem = oApp.createItem(olMailItem)
'***** Use the outlook application object and create a mail item^
oItem.attachments.Add ("\\FP06\common$\Facilities\Eurest - Restaurant\Menus\Menu.doc")
'***** Add an attachment if you want one.^
oItem.To = "someone@somewhere.co.uk"
'***** Set the recipient(s)^
oItem.Body = "Its Saturday. Change the menu."
'***** Set your body text (the message that the recipient will receive)^
oItem.Send
'***** Send it^
Set oApp = Nothing
'***** Clean up^
saturday
'***** Call saturday macro^
ElseIf WeekDay(Now) = 1 Then
'***** If its sunday today^
sunday
'***** Call the sunday macro^
End If
End Sub
Sub saturday()
Do While Time <> "23:59:59"
'***** While it isn't 1 second before midnight on saturday^
If Time = "23:59:59" Then Application.OnTime Now + TimeValue("00:00:05"), "sendmenu.xls!sheet1.sunday"
'***** Keep checking it isn't 1 second before midnight and if it is, wait for 5 seconds and call the sunday routine^
Loop
'***** Loop round the do while routine again^
End Sub
Sub sunday()
Do While Time <> "23:59:59"
'***** While it isn't 1 second to midnight on Sunday^
If Time = "23:59:59" Then Application.OnTime Now + TimeValue("7:59:59"), "sendmenu.xls!sheet1.sendIt"
'***** keep checking it isn't 1 second before midnigh and if it is, wait for 8 hours then call sendIt routine^
Loop
'***** Loop around the do while routine again
End Sub
Sub sendIt()
If WeekDay(Now) = 7 Then
'***** If its Saturday^
saturday
'***** Call the saturday routine^
ElseIf WeekDay(Now) = 1 Then
'***** If its sunday^
sunday
'***** Call the sunday routine^
Else
'***** otherwise?^
Set oApp = CreateObject("outlook.application")
'***** Create an outlook application object^
Set oItem = oApp.createItem(olMailItem)
'***** Use the outlook application object and create a mail item^
oItem.attachments.Add ("\\FP06\common$\Facilities\Eurest - Restaurant\Menus\Menu.doc")
'***** Add an attachment^
oItem.To = "Support Team"
'***** Define the recipient(s)^
oItem.Body = "Hi," & Chr(13) & Chr(13) & "Please find attached this weeks menu. You can access the ordering system from within the attached menu." & Chr(13) & Chr(13) & "Regards" & Chr(13) & "Joe"
'***** Define your message text^ (use the '& chr(13)' for line breaks inside the message)
oItem.Send
'***** Send it^
Set oApp = Nothing
'***** Clean up^
'***** Insert 'exit sub' here in break mode to kill this routine.
evalDay
'***** Go back to the start ^
end sub
Help appreciated.
Thanks
Joe
Bookmarks