Setting Outlook calendar dates with excel rows

legogeek

New Member
Joined
Mar 1, 2011
Messages
28
Pardon me as I am possibly looking for this very same ability but don't fully comprehend VBA very well.
  • Does this code allow an Excel sheet with each row having one date (no duplicates in the column range) to be able to post updating ability to an Outlook Calendar? (ie. if the content of the description changes in Excel it will update the Outlook Calendar?)
  • Also, would this work in Excel 2010?
  • Furthermore, can it be configured to be an All Day event rather than a start/end time?
:rolleyes: I'm primarily interested if this code has the ability of updating/changing information that is already in an Outlook Calendar.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi there, welcome to the board!

I moved your post to its own thread instead of piggy-backing on another.

NB: the thread referenced is http://www.mrexcel.com/forum/showthread.php?t=474092

To answer your questions:
  • No
  • Yes
  • Yes

For the No answer, there are workarounds. You could loop through a range of cells and add them to the calendar if you wish. I would recommend checking to see if they exist first, and also adding a boolean (True/False) variable to check if you opened a new instance of Outlook or not, that way if you did you can close it and clean up after yourself.

Please post back some details about your data structure, where your header rows are, where your data starts, where your data ends, where the information fields are (which columns are what, i.e. dates, start times, subject data, location, notes, etc), as much information as you can. This will help anybody who looks at your thread be able to supply you with a working solution. The more detailed you are, the quicker you will get a suitable solution.

Some things to note about the referenced thread. It uses Early Binding, which means you must select it from the VBE, go to Tools, References, and pick Microsoft Outlook xx.0 Object Library (where the xx is your version number, should only be one if you have one Office version installed). It also assumes you do not have to login when you open Outlook (i.e. a single profile on a local client). If you do need to, you'll need to specify that, but we can code around that. We can build off that code though.

This example assumes you have set a reference as described above, start date in col A, end date in col B, subject in col C, headers in row 1, data from row 2 to 20 (set the differences in the code, you should be able to see where it's commented below)...

Code:
Option Explicit

Sub CreateAppointmentsFromList()

    Dim WB As Workbook
    Dim WS As Worksheet
    Dim rCell As Range
    Dim rCheckCells As Range
    Dim olApp As Outlook.Application
    Dim olApt As Outlook.AppointmentItem
    Dim NS As Outlook.Namespace
    Dim olFolder As Outlook.Folder
    Dim olItemsList As Outlook.Items
    Dim i As Long
    Dim bOLOpen As Boolean
    Dim dStart As Date
    Dim dEnd As Date
    Dim strFilter As String
    Dim iApptCount As Long

    Const iReminderTime As Long = 5

    '///////////////////////////////////////////////////////////////////////////
    'Set Excel variables here
    Set WB = ActiveWorkbook
    Set WS = WB.ActiveSheet
    '/// going to assume col A is Start Date, col B is End Date, col C is Subject
    '/// range is only looking at col A, and offsets the other two cols
    Set rCheckCells = WS.Range("A2:A20")
'    ReDim arrExists(1 To 19)    'to match the size of the range to check (above)
    '///////////////////////////////////////////////////////////////////////////

    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")
    bOLOpen = True
    If olApp Is Nothing Then
        Set olApp = New Outlook.Application
        bOLOpen = False
    End If
    On Error GoTo 0
    Set NS = olApp.GetNamespace("MAPI")
    Set olFolder = NS.GetDefaultFolder(olFolderCalendar)

    For Each rCell In rCheckCells.Cells
    
        dStart = CDate(Int(rCell.Value))
        dEnd = CDate(Int(rCell.Offset(0, 1).Value))
        strFilter = "[Start] = '" & Format(dStart, "m/d/yy h:mm AM/PM") & "' and " & "[End] = '"
        strFilter = strFilter & Format(dEnd + 1, "m/d/yy h:mm AM/PM") & "' and [Subject] = '"
        strFilter = strFilter & rCell.Offset(0, 2).Value & "'"
        Set olItemsList = olFolder.Items.Restrict(strFilter)
        iApptCount = olItemsList.Count
        
        If iApptCount = 0 Then
            Set olApt = olApp.CreateItem(olAppointmentItem)
            olApt.Start = dStart
            olApt.End = dEnd + 1
            olApt.Subject = rCell.Offset(0, 2).Value
            olApt.AllDayEvent = True
            'olApt.Location = rCell.Offset(0, 3).Value '?
            'olApt.Body = rCell.Offset(0, 4).Value '?
            olApt.BusyStatus = olBusy
            olApt.ReminderMinutesBeforeStart = iReminderTime
            olApt.ReminderSet = True
            olApt.Save
        End If
        
    Next rCell

    If bOLOpen = False Then olApp.Quit

End Sub
 
Upvote 0
Please post back some details about your data structure, where your header rows are, where your data starts, where your data ends, where the information fields are (which columns are what, i.e. dates, start times, subject data, location, notes, etc), as much information as you can. This will help anybody who looks at your thread be able to supply you with a working solution. The more detailed you are, the quicker you will get a suitable solution.
The information I'd be using relates to what is best described as a complex Staff Day Off recorder (sheet:"2011" - staff names in columns and dates listed in rows). Where the name and the date cross I place an acronym (eg. "df" = day off, "na" = not available, "hd" = Holiday, etc...). We have about 50 staff that we are recording there days off, holidays, and a handful of other categories.
On another sheet, "2011 COPYCal", I had someone help me with some VBA to create a function called "Concatenator" - basically concantinating items based on criteria. It will CONCATENATE peoples names by looking at a particular row (ie specific date) and look up all the people with "df" and place them in one cell (example: Dave, Bill, Mike). In another cell of the same row it will combine all those with a Holiday, ect... It would be from this sheet "2011 CopyCal" that I would want to update an Outlook Calendar from. The "2011 CopyCal" data changes often enough that I would want to make sure this idea we are talking about actually is going to change the Outlook Calendar events.

At Present - I have hand built months (ie sheet: May, June, July) calendars and hand mapped each cell from "2011 COPYCal" into the corresponding date (eg I:12='2011 COPYCal'!$E$139). The finish product I print out and hand to staff.

So all that to say my data (at present) does not have starttime or endtime information. It has "Date" "Total Gone" "Everyone who is off" "Everyone who is off" "DF & HD" "PTO, DE, OS, NA, FL" "Missionary Off" "Contract Off" "LTD Off" "BC" "Building Closers on Days off or Off site". Keep in mind my column titles have a purpose other than what is for this thread - but I can redesign a worksheet to have more appropriate information to have the ability to get the "Everyone who is off" to an Outlook Calendar.

It also assumes you do not have to login when you open Outlook (i.e. a single profile on a local client). If you do need to, you'll need to specify that, but we can code around that. We can build off that code though.
I probably have the worst case scenario. I have three profiles for Outlook 2010 - the one I would use is connected to google apps. I would prefer to create a specific calendar that would update this "Day off" information - furthermore that I could share (view only) with the staff. On the calendar I'm not sure what would be better - an "all day" event or a made up duration of time that fills the most of the day where more off the names would show in view (ie. day view or week view)

So...that's a lot - I get wordy - hopefully this is not confusing at this point.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top