Consulting

Results 1 to 5 of 5

Thread: Schedule Tasks Every Nine WeekDays

  1. #1
    VBAX Newbie
    Joined
    Dec 2013
    Posts
    4
    Location

    Question Schedule Tasks Every Nine WeekDays

    I am completely new to Outlook and I want to use it as my agenda for school. I have a 9 day cycle and it doesn't apply to the weekends. And when I use the "Every x days" it sometimes lands on the weekends and that makes that my entire schedule is early by 2 days since we don't count the weekends but Outlook does. Can anyone help me with this? Thank you!

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Try this

    Sub Recurring_oddSchedule()
    
    Dim oApptBase As AppointmentItem
    Dim oAppt As AppointmentItem
    
    Dim i As Long
    Dim moreAppts As Long
    Dim oddScheduleWorkingDays As Long
    
    moreAppts = 10 '<-- Whatever more appts after the first you need
    oddScheduleWorkingDays = 9
    
    ' Click on the first appointment
    Set oApptBase = Application.ActiveExplorer.Selection.Item(1)
    
    For i = oddScheduleWorkingDays To (oddScheduleWorkingDays * moreAppts) Step oddScheduleWorkingDays
        Set oAppt = oApptBase.Copy
        oAppt.Subject = "test"
        oAppt.start = WorkingDays(i, oApptBase.start)
        oAppt.Save
        Debug.Print "Appt created: " & oAppt.start & "-" & oAppt.Subject
    Next i
    
    Set oApptBase = Nothing
    Set oAppt = Nothing
    
    Debug.Print " done"
    
    End Sub
    
    Private Function WorkingDays(NumDays As Long, startDate As Date) As Date
        Dim Counter As Long
        Dim ReturnDate As Date
        Counter = NumDays
        ReturnDate = startDate
        Do While Counter > 0
            ReturnDate = ReturnDate + 1
            If Weekday(ReturnDate) >= 2 And Weekday(ReturnDate) <= 6 Then
                Counter = Counter - 1
            End If
        Loop
        WorkingDays = ReturnDate
    End Function

    Beginner help here http://www.slipstick.com/developer/h...ks-vba-editor/
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    VBAX Newbie
    Joined
    Dec 2013
    Posts
    4
    Location
    Thank you that works perfectly but I just need to know how can I modify it so that some days like lets say we have a break a week or something, hoe canI modify it to exclude those days?

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Set moreAptts to the last date before the break, then run it again on the Appts after the break
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Newbie
    Joined
    Dec 2013
    Posts
    4
    Location
    Quote Originally Posted by SamT View Post
    Set moreAptts to the last date before the break, then run it again on the Appts after the break
    Oh ok thank you!

Tags for this Thread

Posting Permissions

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