+ Reply to Thread
Results 1 to 2 of 2

Using a Macro to send data to shared Outlook Calendars

Hybrid View

  1. #1
    Registered User
    Join Date
    02-21-2017
    Location
    Scotland
    MS-Off Ver
    2016
    Posts
    1

    Using a Macro to send data to shared Outlook Calendars

    Hello,

    I am currently setting up a spreadsheet for my office in which we can enter appointments and use a macro to send them to someone's calendar by selecting their name. I currently have this working and sending to calendars that I have made myself but I am stuck with how to send the data to other people. Currently, my macro looks like this:


    Option Explicit
    Public Sub CreateOutlookApptz()
       Sheets("Sheet1").Select
        On Error GoTo Err_Execute
        
        Dim olApp As Outlook.Application
        Dim olAppt As Outlook.AppointmentItem
        Dim blnCreated As Boolean
        Dim olNs As Outlook.Namespace
        Dim CalFolder As Outlook.MAPIFolder
        Dim subFolder As Outlook.MAPIFolder
        Dim arrCal As String
        
        
        Dim i As Long
        
        On Error Resume Next
        Set olApp = Outlook.Application
        
        If olApp Is Nothing Then
            Set olApp = Outlook.Application
             blnCreated = True
            Err.Clear
        Else
            blnCreated = False
        End If
        
        On Error GoTo 0
        
        Set olNs = olApp.GetNamespace("MAPI")
        Set CalFolder = olNs.GetDefaultFolder(olFolderCalendar)
            
        i = 2
        Do Until Trim(Cells(i, 1).Value) = ""
        arrCal = Cells(i, 1).Value
        Set subFolder = CalFolder.Folders(arrCal)
         If Trim(Cells(i, 11).Value) = "" Then
        Set olAppt = subFolder.Items.Add(olAppointmentItem)
             
        
    
        With olAppt
        
        
            .Start = Cells(i, 5)
            .End = Cells(i, 12)
            .Subject = Cells(i, 2)
            .Location = Cells(i, 3)
            .Body = Cells(i, 4)
            .BusyStatus = olBusy
            .ReminderMinutesBeforeStart = Cells(i, 7)
            .ReminderSet = True
            .Save
        
        End With
        Cells(i, 11) = "Imported"
        
        End If
                    
            i = i + 1
            Loop
        Set olAppt = Nothing
        Set olApp = Nothing
         ThisWorkbook.Save
        Exit Sub
        
    Err_Execute:
        MsgBox "An error occurred - Exporting items to Calendar."
        
    End Sub


    In which arrCal is a dropdown field that is currently set to go to test calendars that I have made myself. Any help in this would be greatly appreciated as I have been struggling with this for most of the day. If anyone needs any further information about the spreadsheet feel free to ask.

    Thanks,

    Neilp27
    Last edited by Neilp27; 02-21-2017 at 10:31 AM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Using a Macro to send data to shared Outlook Calendars

    You can use the Namespace.GetSharedDefaultFolder method to access the Calendar folder in another Exchange mailbox - as long as you, or more to the point, the current user has permissions (in Outlook) to do so.

    Code snippet - this temporarily creates an email message so it can resolve the addressee to get the correct calendar

        strName = "DoeJ"
         
        Set oApp = CreateObject("Outlook.Application")
        Set oNS = objApp.GetNamespace("MAPI")
        Set oDummy = objApp.CreateItem(olMailItem)
        Set oRecip = oDummy.Recipients.Add(strName)
        oRecip.Resolve
        If oRecip.Resolved Then
            On Error Resume Next
            Set oFolder = _
              oNS.GetSharedDefaultFolder(oRecip, _
                olFolderCalendar)
            If Not oFolder Is Nothing Then
                Set oAppt = objFolder.Items.Add
                If Not oAppt Is Nothing Then
                    With oAppt
                        .Subject = "Test"
                        .Start = Date + 7
                        .AllDayEvent = True
                        .Save
                    End With
    Partial code only to illustrate the idea, that will not compile.
    Last edited by cytop; 02-21-2017 at 10:43 AM.

+ 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] Help with VB code to send Outlook Meeting Request from Shared Calendar via excel
    By rv02 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2017, 09:50 AM
  2. Replies: 1
    Last Post: 02-06-2017, 09:50 AM
  3. Replies: 1
    Last Post: 02-06-2017, 09:50 AM
  4. Replies: 0
    Last Post: 02-06-2017, 07:47 AM
  5. Import data from Outlook shared calendars
    By colombiano254 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-22-2015, 04:08 AM
  6. Create MsgBox When Shared Calendars Opened
    By races23 in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 04-15-2013, 04:35 PM
  7. Exporting Excel data into Outlook calendars: Changing an Outlook VBA to Excel VBA
    By spaceporker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-19-2012, 11:39 PM

Tags for this Thread

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