Results 1 to 4 of 4

Thread: Excel: Import Excel Info into Outlook

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Excel: Import Excel Info into Outlook

    I want to transfer information that's in an Excel spreadsheet into a calendar in outlook. I've written the code below to create new appointments but the appointments are created in my main calendar. How do I direct them to be written in another calendar named Schedule in my mailbox or into a calendar that is in a public folder. The preferred option would be a public folder with the following tree:

    \\Public Folders\All Public Folders\Tech Schedule\

    Here is the code that has been written:



    Sub AddAppointments()


    ' Create the Outlook session

    Set myOutlook = CreateObject("Outlook.Application")

    ' Start at row 2
    r = 2

    Do Until Trim(Cells(r, 1).Value) = ""
    ' Create the AppointmentItem
    Set myApt = myOutlook.createitem(1)
    ' Set the appointment properties
    myApt.Subject = Cells(r, 1).Value
    myApt.Location = Cells(r, 2).Value
    myApt.Start = Cells(r, 3).Value
    myApt.Duration = Cells(r, 4).Value
    ' If Busy Status is not specified, default to 2 (Busy)
    If Trim(Cells(r, 5).Value) = "" Then
    myApt.BusyStatus = 2
    Else
    myApt.BusyStatus = Cells(r, 5).Value
    End If
    If Cells(r, 6).Value > 0 Then
    myApt.ReminderSet = True
    myApt.ReminderMinutesBeforeStart = Cells(r, 6).Value
    Else
    myApt.ReminderSet = False
    End If
    myApt.Body = Cells(r, 7).Value
    myApt.Save
    r = r + 1
    Loop
    End Sub

    Thanks in advance for the help!

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel: Import Excel Info into Outlook

    code or highlight tags would be nice
    vb Code:
    1. Sub AddAppointments()
    2.  
    3.  
    4. ' Create the Outlook session
    5.  
    6. Set myOutlook = CreateObject("Outlook.Application")
    7.  
    8. ' Start at row 2
    9. r = 2
    10.  
    11. Do Until Trim(Cells(r, 1).Value) = ""
    12. ' Create the AppointmentItem
    13. Set myApt = myOutlook.createitem(1)
    14. ' Set the appointment properties
    15. myApt.Subject = Cells(r, 1).Value
    16. myApt.Location = Cells(r, 2).Value
    17. myApt.Start = Cells(r, 3).Value
    18. myApt.Duration = Cells(r, 4).Value
    19. ' If Busy Status is not specified, default to 2 (Busy)
    20. If Trim(Cells(r, 5).Value) = "" Then
    21. myApt.BusyStatus = 2
    22. Else
    23. myApt.BusyStatus = Cells(r, 5).Value
    24. End If
    25. If Cells(r, 6).Value > 0 Then
    26. myApt.ReminderSet = True
    27. myApt.ReminderMinutesBeforeStart = Cells(r, 6).Value
    28. Else
    29. myApt.ReminderSet = False
    30. End If
    31. myApt.Body = Cells(r, 7).Value
    32. myApt.Save
    33. r = r + 1
    34. Loop
    35. End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Re: Excel: Import Excel Info into Outlook

    I'm just starting out writing VBA so please be patient with me. Let me revise this to code that creates a single appointment. Need to direct creation of this appointment to a calendar that is in a public folder not my current mailbox calendar.

    Code:
    1. Sub AddAppointments()
    2. ' Create the Outlook session
    3. Set myOutlook = CreateObject("Outlook.Application")
    4. ' Create the AppointmentItem
    5. Set myApt = myOutlook.createitem(1)
    6. ' Set the appointment properties
    7. myApt.Subject = "Matt"
    8. myApt.Location = "Office"
    9. myApt.Start = "4/27/2011 12:00:00 PM"
    10. myApt.Duration = "30"
    11. myApt.BusyStatus = 2
    12. myApt.ReminderSet = True
    13. myApt.ReminderMinutesBeforeStart = "0"
    14. myApt.ReminderSet = False
    15. myApt.Body = "Meeting With Boss"
    16. myApt.Save
    17. End Sub
    I appreciate any assistance that you can provide.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel: Import Excel Info into Outlook

    as i do not have outlook installed, i can not be sure how to get the correct folder object
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width