Results 1 to 4 of 4

Whats up with this code?

Threaded View

  1. #1
    Registered User
    Join Date
    08-14-2006
    Posts
    29

    Whats up with this code?

    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
    Last edited by LFCFan; 10-16-2006 at 06:16 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1