+ Reply to Thread
Results 1 to 2 of 2

Excel VBA macro to outlook shared agenda

  1. #1
    Registered User
    Join Date
    05-07-2015
    Location
    Nederland
    MS-Off Ver
    2013
    Posts
    2

    Excel VBA macro to outlook shared agenda

    Hi Guys,

    I'm trying to figure out what im doing wrong with my macro:

    The appointments need to go in the testagenda calendar.
    Now the appointments go in my own calendar and i get blank appointments on the today date in de test agenda.

    Can anyone see where my fault is?


    Thanks!



    VBA:

    Sub MaakAfspraken()

    Dim olApp As Outlook.Application
    Dim olNS As Outlook.Namespace
    Dim olDefualtFolder As Outlook.Folder
    Dim olDestinationFolder As Outlook.Folder
    Dim olFolders As Outlook.Folders
    Dim olItems As Outlook.Items
    Dim olAppt As Outlook.AppointmentItem

    Set olApp = CreateObject("Outlook.Application")
    Set olNS = olApp.GetNamespace("MAPI")

    Set olFldr = olApp.GetNamespace("MAPI").GetDefaultFolder(9).Folders("testagenda")
    Set olAppt = olFldr.Items.Add

    ' Set the Defualt Folder to the appropriate folder type
    Set olDefualtFolder = olNS.GetDefaultFolder(olFolderCalendar)

    'get the defualt calenders collection of sub folders
    Set olFolders = olDefualtFolder.Folders

    'get the specific destination folder
    Set olDestinationFolder = olFolders.Item("testagenda")

    'get the collection of items in destination folder
    Set olItems = olDestinationFolder.Items

    ' Add an item to the collection
    Set olAppt = olItems.Add(olAppointmentItem)

    ' Add an item to the collection
    Set olAppt = olItems.Add(olAppointmentItem)



    Range("A9").Select
    'olApp.visbible = yes
    Do
    Set olApt = olApp.CreateItem(olAppointmentItem)
    With olApt
    .Start = ActiveCell.Value + ActiveCell.Offset(0, 1).Value
    If Not IsEmpty(ActiveCell.Offset(0, 3).Value) Then
    .End = .Start + ActiveCell.Offset(0, 3).Value
    Else
    .End = ActiveCell.Value + ActiveCell.Offset(0, 2).Value
    End If
    .Subject = ActiveCell.Offset(0, 4).Value
    .Location = ActiveCell.Offset(0, 5).Value
    If Not IsEmpty(ActiveCell.Offset(0, 6).Value) Then
    olApt.MeetingStatus = olMeeting
    .RequiredAttendees = ActiveCell.Offset(0, 6).Value
    .OptionalAttendees = ActiveCell.Offset(0, 7).Value
    End If
    .Body = ActiveCell.Offset(0, 8).Value
    If ActiveCell.Offset(0, 9).Value = "Bezet" Then
    .BusyStatus = olBusy
    ElseIf ActiveCell.Offset(0, 9).Value = "Vrij" Then
    .BusyStatus = olFree
    ElseIf ActiveCell.Offset(0, 9).Value = "Voorlopig bezet" Then
    .BusyStatus = olTentative
    ElseIf ActiveCell.Offset(0, 9).Value = "Niet aanwezig" Then
    .BusyStatus = olOutOfOffice
    ElseIf IsEmpty(ActiveCell.Offset(0, 9).Value) Then
    .BusyStatus = olBusy
    End If
    If Not IsEmpty(ActiveCell.Offset(0, 10).Value) Then
    .ReminderMinutesBeforeStart = ActiveCell.Offset(0, 10).Value
    Else
    .ReminderMinutesBeforeStart = 60
    End If
    .ReminderSet = True
    .Save
    .Send
    End With
    Set olApt = Nothing
    ActiveCell.Offset(1, 0).Select
    Loop Until IsEmpty(ActiveCell)

    Range("A9").Select


    'Set reminder for 1 day before.
    olAppt.ReminderMinutesBeforeStart = 1440
    olAppt.AllDayEvent = True
    olAppt.Save

    MsgBox "You have just updated the outlook calendar. ", vbInformation, Title:="Outlook Calendar Updated"

    ' move item to desired destination folder - no longer needed
    ' olAppt.Move olDestinationFolder

    SubExit:
    Set olAppt = Nothing
    Set olDefualtFolder = Nothing
    Set olFolders = Nothing
    Set olDestinationFolder = Nothing

    Set olNS = Nothing
    Set olApp = Nothing

    Exit Sub

    SubError:
    MsgBox "Error Number: " & Err.Number & " - " & Err.Description
    Resume SubExit

    End Sub
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-07-2015
    Location
    Nederland
    MS-Off Ver
    2013
    Posts
    2

    Re: Excel VBA macro to outlook shared agenda

    Anyone knows this?

+ 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] Import MailItem properties from Outlook shared folder(s) to Excel
    By kaptenstofil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2014, 05:26 AM
  2. Create Outlook Reminder on Excel and transfered to outlook by macro
    By Benjamin2008 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2013, 03:23 PM
  3. [SOLVED] VBA Macro to print to Pdf format and place as attachment in Outlook (Excel & Outlook 2007)
    By Webman1012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2013, 01:25 PM
  4. Excel Macro - Linking dates from Excel to a Shared Outlook Calendar
    By cg7131 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2011, 11:08 AM
  5. excel to a shared outlook appointment
    By boemboem in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2008, 02:24 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