+ Reply to Thread
Results 1 to 18 of 18

Trouble creating outlook event from

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Trouble creating outlook event from

    Hey guys,

    I was wondering if someone could help me get some VBA code to create a task in outlook and something to keep track which items have already been exported to excel. I only need to export the time, date and the subject. The rest is not important. It will be on a seperate worksheet. I am using office 2010. I have seen a lot of code around the web but it only shows the code and not the format and location where to enter the contents. All I want to do is create reminders for which I can define the time of the reminder and the text i want to be reminded of. And if possible a cell marked with a X or something if it already has been exported.

    any help would be greatly appreciated!

    and thanks in advance

  2. #2
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    I have found the following code on the net which does exactly what I need it to do, the only thing is I get duplicate events. Does anyone know the VBA code to prevent this from doing so? I am a complete noob in VBA


    Sub AddOutLookTask()
    ' add a refrence to Microsoft outlook object library
             Dim appOutLook As Outlook.Application
             Dim taskOutLook As Outlook.AppointmentItem
             Dim data As Worksheet, subject As String, body As String
             Dim wen As Date
             Set appOutLook = CreateObject("Outlook.Application")
             Set taskOutLook = appOutLook.CreateItem(olAppointmentItem)
             Set data = ThisWorkbook.Worksheets("Agenda") ' change worksheetname as required
             For i = 2 To Application.CountA(Sheets("Agenda").Range("A:A")) ' loop through each row starting at row 2  (loop uses column A as a count - ensure column A always contains a name
                Set taskOutLook = appOutLook.CreateItem(olAppointmentItem)
                subject = data.Cells(i, 1)
                body = "You have a meeting with " & subject
                wen = DateValue(data.Cells(i, 2)) + data.Cells(i, 3)
                If InStr(data.Cells(i, 4), "hr") Then ' does duration contain 'hr'
                   durationarray = Split(data.Cells(i, 4), " ") ' get digits before first space
                   Duration = Val(durationarray(0))
                Else
                   durationarray = Split(data.Cells(i, 4), " ")
                   Duration = Val(durationarray(0)) / 60 'if duration does not contain hr  (i.e. mins) then convert mins to decimal of an hour  (30 mins = 0.5)
                End If
                reminder1 = Split(data.Cells(i, 5), " ") ' assume always days and get digits before first space
                Reminder = reminder1(0)
                With taskOutLook
                   .subject = subject
                   .body = body
                   .ReminderSet = True
                   .ReminderMinutesBeforeStart = Reminder * 24 * 60 ' reminder in hours converted to minutes
                   .Duration = Duration * 60 ' duration converted to minutes
                   .Start = wen ' start date/time
                   .Save
                End With
             Next
             Set appOutLook = Nothing
             Set taskOutLook = Nothing
             Set data = Nothing
             Set taskOutLook = Nothing
         End Sub

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble creating outlook event from

    Hi Nick

    Look at this link...

    http://www.excelforum.com/excel-prog...-calendar.html
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    Hey John

    Thanks for the link but I have a few questions. How do I know what to put where. Because the code I've got now does work in the following format: Name, Date, Time, Duration, Reminder.
    As I said I don't know that much about VBA and I can't seem to make it up by looking at the code.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble creating outlook event from

    Hi Nick

    If you'll post a sample file of your data I'll be happy to look at it. Make certain the Structure of your sample file is the same as your actual workbook.

    Make sure there is just enough data to demonstrate your need. INCLUDE ANY CODE YOU'RE USING OR HAVE TRIED.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    What is the NAME of the Calendar in which you'll be creating the appointments?

  6. #6
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    Thanks for taking the effort for looking in to this!

    I only have the code I have posted beforehand (the one that works but duplicates)
    The sample file is included in this post, the format is exactly the same and how it will be used in making the agenda.

    I guess the name of the calendar is the default one, I am testing it with a @hotmail.com account but it also works with the companies' domain in the default calendar.

    Thanks again!
    Attached Files Attached Files

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble creating outlook event from

    Hi Nick

    Please populate your Workbook with some sample data...three or four items will suffice.

  8. #8
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    Here you go
    Attached Files Attached Files

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble creating outlook event from

    Hi Nick

    Try this Code in the attached...

    Option Explicit
    Sub AddOutLookTask()
       ' add a refrence to Microsoft outlook object library
       Dim appOutLook   As Outlook.Application
       Dim taskOutLook  As Outlook.AppointmentItem
       Dim myItem       As Outlook.AppointmentItem
       Dim myItems      As Outlook.Items
       Dim data         As Worksheet
       Dim subject      As String
       Dim body         As String
       Dim wen          As Date
       Dim i            As Long
       Dim olNs         As Namespace
       Dim durationarray() As String
       Dim Duration     As Double
       Dim reminder1()  As String
       Dim Reminder     As Double
    
       Set appOutLook = CreateObject("Outlook.Application")
       Set olNs = appOutLook.GetNamespace("MAPI")
       Set myItems = olNs.GetDefaultFolder(olFolderCalendar).Items
    
       Set taskOutLook = appOutLook.CreateItem(olAppointmentItem)
       Set data = ThisWorkbook.Worksheets("Agenda")   ' change worksheetname as required
       For i = 2 To Application.CountA(Sheets("Agenda").Range("A:A"))   ' loop through each row starting at row 2  (loop uses column A as a count - ensure column A always contains a name
          subject = data.Cells(i, 1)
          body = "You have a meeting with " & subject
          wen = DateValue(data.Cells(i, 2)) + data.Cells(i, 3)
          If InStr(data.Cells(i, 4), "hr") Then   ' does duration contain 'hr'
             durationarray = Split(data.Cells(i, 4), " ")   ' get digits before first space
             Duration = Val(durationarray(0))
          Else
             durationarray = Split(data.Cells(i, 4), " ")
             Duration = Val(durationarray(0)) / 60   'if duration does not contain hr  (i.e. mins) then convert mins to decimal of an hour  (30 mins = 0.5)
          End If
          reminder1 = Split(data.Cells(i, 5), " ")   ' assume always days and get digits before first space
          Reminder = reminder1(0)
    
          Set myItem = myItems.Find("[Subject]=" & Chr(34) & subject & Chr(34))
    
          If Not myItem Is Nothing Then
             If myItem.subject = subject And _
                myItem.Duration / 60 = Duration And _
                myItem.Start = wen Then
                MsgBox subject & " Already Scheduled"
                GoTo Skip_Me
             End If
    
          Else
             Set taskOutLook = appOutLook.CreateItem(olAppointmentItem)
             With taskOutLook
                .subject = subject
                .body = body
                .ReminderSet = True
                .ReminderMinutesBeforeStart = Reminder * 24 * 60   ' reminder in hours converted to minutes
                .Duration = Duration * 60   ' duration converted to minutes
                .Start = wen   ' start date/time
                .Save
             End With
          End If
          Set myItem = myItems.FindNext
    Skip_Me:
       Next
       Set appOutLook = Nothing
       Set taskOutLook = Nothing
       Set data = Nothing
       Set taskOutLook = Nothing
    End Sub
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    Thanks! this is exactly what I wanted, works like a charm! Thanks again for your help

    Nick

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble creating outlook event from

    You're welcome...glad I could help. Thanks for the Rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  12. #12
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    Hey for some reason my last question did not get through. I was wondering if it is possible for the already scheduled message to popup only once, this as about 20 30 items are added each day and the boxes will pile up

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble creating outlook event from

    Hi Nick

    Do you really require the message? If so, what are you looking for, one message with ALL the "Already Scheduled" items?

  14. #14
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    Not having a message is a option as well, either that or one message like some items have already been scheduled and have not been added as confirmation

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble creating outlook event from

    Let me look at it...I have some ideas.

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble creating outlook event from

    Hi Nick

    Replace the Code with this...

    Option Explicit
    Sub AddOutLookTask()
       ' add a refrence to Microsoft outlook object library
       Dim appOutLook   As Outlook.Application
       Dim taskOutLook  As Outlook.AppointmentItem
       Dim myItem       As Outlook.AppointmentItem
       Dim myItems      As Outlook.Items
       Dim data         As Worksheet
       Dim subject      As String
       Dim body         As String
       Dim wen          As Date
       Dim i            As Long
       Dim olNs         As Namespace
       Dim durationarray() As String
       Dim Duration     As Double
       Dim reminder1()  As String
       Dim Reminder     As Double
       Dim myArray()    As Variant
       Dim msgString    As String
    
       ReDim myArray(0)
       Set appOutLook = CreateObject("Outlook.Application")
       Set olNs = appOutLook.GetNamespace("MAPI")
       Set myItems = olNs.GetDefaultFolder(olFolderCalendar).Items
    
       '   Set taskOutLook = appOutLook.CreateItem(olAppointmentItem)
       Set data = ThisWorkbook.Worksheets("Agenda")   ' change worksheetname as required
       For i = 2 To Application.CountA(Sheets("Agenda").Range("A:A"))   ' loop through each row starting at row 2  (loop uses column A as a count - ensure column A always contains a name
          subject = data.Cells(i, 1)
          body = "You have a meeting with " & subject
          wen = DateValue(data.Cells(i, 2)) + data.Cells(i, 3)
          If InStr(data.Cells(i, 4), "hr") Then   ' does duration contain 'hr'
             durationarray = Split(data.Cells(i, 4), " ")   ' get digits before first space
             Duration = Val(durationarray(0))
          Else
             durationarray = Split(data.Cells(i, 4), " ")
             Duration = Val(durationarray(0)) / 60   'if duration does not contain hr  (i.e. mins) then convert mins to decimal of an hour  (30 mins = 0.5)
          End If
          reminder1 = Split(data.Cells(i, 5), " ")   ' assume always days and get digits before first space
          Reminder = reminder1(0)
    
          '      ReDim myArray(0)
          Set myItem = myItems.Find("[Subject]=" & Chr(34) & subject & Chr(34))
    
          If Not myItem Is Nothing Then
             If myItem.subject = subject And _
                myItem.Duration / 60 = Duration And _
                myItem.Start = wen Then
    
                myArray(UBound(myArray)) = subject & " already acheduled"
                ReDim Preserve myArray(UBound(myArray) + 1)
                '            MsgBox subject & " Already Scheduled"
                GoTo Skip_Me
             End If
    
          Else
             Set taskOutLook = appOutLook.CreateItem(olAppointmentItem)
             With taskOutLook
                .subject = subject
                .body = body
                .ReminderSet = True
                .ReminderMinutesBeforeStart = Reminder * 24 * 60   ' reminder in hours converted to minutes
                .Duration = Duration * 60   ' duration converted to minutes
                .Start = wen   ' start date/time
                .Save
             End With
          End If
          Set myItem = myItems.FindNext
    Skip_Me:
       Next
       On Error Resume Next
       ReDim Preserve myArray(UBound(myArray) - 1)
       On Error GoTo 0
       msgString = Join(myArray, vbCr)
       If Not IsError(Application.Match("*", (myArray), 0)) Then
          MsgBox msgString
       End If
       Set appOutLook = Nothing
       Set taskOutLook = Nothing
       Set data = Nothing
       Set taskOutLook = Nothing
    End Sub
    Last edited by jaslake; 04-08-2016 at 10:52 AM.

  17. #17
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    I'm going to try the code now, I'll you know the results!

  18. #18
    Registered User
    Join Date
    03-31-2016
    Location
    Netherlands
    MS-Off Ver
    2007, 2013
    Posts
    17

    Re: Trouble creating outlook event from

    Thanks again! works great and now does exactly what i need it to do thanks for all the effort you've put into it!

    Nick

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Trouble with the 'worksheet_selectionchange' event
    By fosters_ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-08-2014, 05:05 AM
  2. [SOLVED] Having Trouble Modifying Excel Sheet With Outlook
    By bullo1854 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2014, 10:31 AM
  3. [SOLVED] Trouble stopping an Application.OnTime event
    By phuz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2012, 09:34 AM
  4. Trouble with Selection_Change Event
    By jman0707 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2008, 01:28 PM
  5. Trouble triggering an event when UsedRange >=A1500?
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2006, 11:50 PM
  6. Trouble using UsedRange to trigger an event??
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-19-2006, 10:29 PM
  7. Event trouble...
    By Ernst Guckel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2005, 06:06 AM

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