+ Reply to Thread
Results 1 to 2 of 2

Creating calendar item in non-default calendar

Hybrid View

  1. #1
    Registered User
    Join Date
    06-19-2007
    Location
    Sydney, Australia
    MS-Off Ver
    2013
    Posts
    72

    Creating calendar item in non-default calendar

    Hi All

    It's been a while since I have posted here but I am completely stumped with this one and looking for help.

    I have the following code to create an appointment in Outlook using data froma worksheet:

    Sub CreateAppointment()
    
        Dim oApp As Outlook.Application
        Dim oNameSpace As Namespace
        Dim oItem As AppointmentItem
        Dim RowNumber As Integer
        Dim AppStartTime As String
        Dim AppEndTime As String
                    
        RowNum = ActiveCell.Row
        
        On Error Resume Next
    ' check if Outlook is running
        Set oApp = GetObject("Outlook.Application")
        If Err <> 0 Then
    'if not running, start it
        Set oApp = CreateObject("Outlook.Application")
    
        End If
        
        Set oNameSpace = oApp.GetNamespace("MAPI")
        Set oItem = oApp.CreateItem(olAppointmentItem)
            
    '' Get Start Date/Time
        If Worksheets("OrderDetails").Range("R" & RowNum).Value = "" Then
            AppStartTime = Now
        Else
            AppStartTime = Worksheets("OrderDetails").Range("R" & RowNum).Value + Worksheets("OrderDetails").Range("S" & RowNum).Value
        End If
    
    '' Get End Time
        If Worksheets("OrderDetails").Range("T" & RowNum).Value = "" Then
            AppEndTime = AppStartTime + 0.5
        Else
            AppEndTime = Worksheets("OrderDetails").Range("R" & RowNum).Value + Worksheets("OrderDetails").Range("T" & RowNum).Value
        End If
    
    ''Adjust Details of Calendar Item
        With oItem
    
            .Subject = Worksheets("OrderDetails").Range("N" & RowNum)
            .Start = AppStartTime
            .End = AppEndTime
    
            .AllDayEvent = False
            .Importance = olImportanceNormal
            .Location = Worksheets("OrderDetails").Range("O" & RowNum)
    
            .ReminderSet = True
            .ReminderMinutesBeforeStart = "10"
            .ReminderPlaySound = True
            .ReminderSoundFile = "C:\Windows\Media\Ding.wav"
    
            Select Case 2 
                Case 1
                    .Display
                Case 2
                    .Save
            End Select
    
        End With
          
          
    Set oApp = Nothing
    Set oNameSpace = Nothing
    Set oItem = Nothing
    
    End Sub
    This is fine for creating a calendar item in the default calendar however I am trying to create (or create then move) the appointment in a shared calendar.

    I have found several examples however I can't seem to get any of them to work with my code. Any help would be greatly appreciated.

    Thanks
    Mark
    Last edited by Gus80; 10-25-2015 at 07:26 PM.

  2. #2
    Registered User
    Join Date
    06-19-2007
    Location
    Sydney, Australia
    MS-Off Ver
    2013
    Posts
    72

    Re: Creating calendar item in non-default calendar

    Hi Guys

    I know it's not pretty, but I managed to get it to work:


    Sub CreateAppointment2()
    
        Dim oApp As Outlook.Application
        Dim oItem As AppointmentItem
        Dim RowNumber As Integer
        Dim AppStartTime As String
        Dim AppEndTime As String
        
        Dim onamespace2 As Outlook.Namespace
        Dim recipient As Outlook.recipient
        Dim calendarFolder As Outlook.Folder
        Dim DestCal As String
                        
        RowNum = ActiveCell.Row
        
        On Error Resume Next
    ' check if Outlook is running
        Set oApp = GetObject("Outlook.Application")
        If Err <> 0 Then
    ' if not running, start it
        Set oApp = CreateObject("Outlook.Application")
    
        End If
        
       '' Get Start Date/Time
        If Worksheets("OrderDetails").Range("R" & RowNum).Value = "" Then
            AppStartTime = Now
        Else
            AppStartTime = Worksheets("OrderDetails").Range("R" & RowNum).Value + Worksheets("OrderDetails").Range("S" & RowNum).Value
        End If
    
    '' Get End Time
        If Worksheets("OrderDetails").Range("T" & RowNum).Value = "" Then
            AppEndTime = AppStartTime + 0.5
        Else
            AppEndTime = Worksheets("OrderDetails").Range("R" & RowNum).Value + Worksheets("OrderDetails").Range("T" & RowNum).Value
        End If
        
        CalDest = Worksheets("OrderDetails").Range("U" & RowNum).Value
        
    Set onamespace2 = oApp.GetNamespace("MAPI")
    Set recipient = onamespace2.CreateRecipient(CalDest)
    
    recipient.Resolve
                
    If recipient.Resolved Then
        
        Set calendarFolder = onamespace2.GetSharedDefaultFolder(recipient, olFolderCalendar)
        Set oNameSpace = oApp.GetNamespace("MAPI")
        Set oItem = calendarFolder.Items.Add(olAppointmentItem)
        
        With oItem
            .Subject = Worksheets("OrderDetails").Range("N" & RowNum)
            .Start = AppStartTime
            .End = AppEndTime
    
            .AllDayEvent = False
            .Importance = olImportanceNormal
            .Location = Worksheets("OrderDetails").Range("O" & RowNum)
    
            .ReminderSet = True
            .ReminderMinutesBeforeStart = "10"
            .ReminderPlaySound = True
            .ReminderSoundFile = "C:\Windows\Media\Ding.wav"
    
            Select Case 1
                Case 1
                    .Display
                Case 2
                    .Save
            End Select
    
        End With
        
    End If
        
        
    Set oApp = Nothing
    Set oItem = Nothing
    Set onamespace2 = Nothing
    Set recipient = Nothing
    
    
    
    
    End Sub

+ 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. [SOLVED] Calendar entry meeting in lotus notes calendar with macro
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-16-2016, 05:45 AM
  2. Create appointments in Non Default Calendar
    By nobox in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-17-2015, 10:21 PM
  3. Calendar functions - linking work activities with formatted dates to calendar
    By SKSS in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2012, 06:38 PM
  4. Calendar VBA auto filling week and month based on calendar entry.
    By perrymagic in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2011, 02:00 PM
  5. Setting color category in Outlook calendar item
    By Geronimo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2011, 02:57 AM
  6. Change MS outlook default calendar folder
    By DB4284 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2010, 06:30 AM
  7. Default date in Userform Calendar
    By AndyE in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-05-2010, 01:15 PM
  8. Replies: 0
    Last Post: 03-27-2008, 04:36 PM

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