Link to home
Start Free TrialLog in
Avatar of mvalencia2003
mvalencia2003Flag for United States of America

asked on

Import Holiday Calendar

Is there a way to Import a Holiday calendar into a Outlook account ..
??


Thanks ,,
Avatar of omgang
omgang
Flag of United States of America image

I utilize a vbscrpt to add annual holidays to Outlook calendar.  Are you wanting something similar?
OM Gang
Here's a sample
OM Gang

Const olFolderCalendar = 9
Const olAppointmentItem = 1
Const olOutOfOffice = 3

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar) 

Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "January 1, 2015", "New Year’s Day"    
objDictionary.Add "January 19, 2015", "Martin Luther King, Jr. Day"    
objDictionary.Add "February 16, 2015", "Presidents’ Day"
objDictionary.Add "May 25, 2015", "Memorial Day"
objDictionary.Add "July 3, 2015", "Independence Day"
objDictionary.Add "September 7, 2015", "Labor Day"
objDictionary.Add "October 12, 2015", "Columbus Day"
objDictionary.Add "November 11, 2015", "Veteran’s Day"
objDictionary.Add "November 26, 2015", "Thanksgiving Day"
objDictionary.Add "December 25, 2015", "Christmas Day"

colKeys = objDictionary.Keys

For Each strKey in colKeys
    dtmHolidayDate = strKey
    strHolidayName = objDictionary.Item(strKey)

    Set objHoliday = objOutlook.CreateItem(olAppointmentItem)  
    objHoliday.Subject = strHolidayName
    objHoliday.Start = dtmHolidayDate & " 9:00 AM"
    objHoliday.End = dtmHolidayDate & " 10:00 AM"
    objHoliday.AllDayEvent = True
    objHoliday.ReminderSet = False
    objHoliday.BusyStatus = olOutOfOffice
    objHoliday.Save
Next

Wscript.Echo "Holidays have been added to Outlook calendar"

Open in new window

What format is the caledndar in? PST? All you need to do is Open Outlook and import the new calendar.

- open outlook
- click file open
- click import
- import from another program or file
- select Outlook Data FIle (PST)
- point to the path of the pst file

done

Will.
Avatar of mvalencia2003

ASKER

omgang,

Do I just run that from PowerShell ..??
Copy the code and past into Notepad.  Save as a .vbs file, e.g. 2015OutlookHolidays.vbs.  Double click to execute/run.
OM Gang
So I have to be logged on to the computer with that account username .. right?  If I have the calendar as a shared calendar this won't work ..

??
The script I posted will not update a shared calendar.  This line
Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar)
is instantiating a folder object for the default Outlook Calendar, i.e. yours or whoever's Outlook profile you are logged on with.

Options:
1) If the shared calendar is a resource box/room/etc. that is shared by many, create an Outlook Profile for that resource box/room/etc., launch Outlook with that profile and then run the script.
2) I believe I can modify the script to update a different calendar; this will, of course, be dependent upon permissions, e.g. if you don't have permissions to add/update the calendar it will fail.
OM Gang
What would need to be modified to update a shared calendar?  ..
-
Give this a try.  It works for me on a shared calendar that I have permissions to add/update.  Instead of hard coding in a calendar name I used a folder picker dialog.
OM Gang


Const olFolderCalendar = 9
Const olAppointmentItem = 1
Const olOutOfOffice = 3


Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objCalendar = objNamespace.PickFolder

Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "January 1, 2015", "New Year’s Day"    
objDictionary.Add "January 19, 2015", "Martin Luther King, Jr. Day"    
objDictionary.Add "February 16, 2015", "Presidents’ Day"
objDictionary.Add "May 25, 2015", "Memorial Day"
objDictionary.Add "July 3, 2015", "Independence Day"
objDictionary.Add "September 7, 2015", "Labor Day"
objDictionary.Add "October 12, 2015", "Columbus Day"
objDictionary.Add "November 11, 2015", "Veteran’s Day"
objDictionary.Add "November 26, 2015", "Thanksgiving Day"
objDictionary.Add "December 25, 2015", "Christmas Day"

colKeys = objDictionary.Keys

For Each strKey in colKeys
    dtmHolidayDate = strKey
    strHolidayName = objDictionary.Item(strKey)

    Set objHoliday = objCalendar.Items.Add

    objHoliday.Subject = strHolidayName
    objHoliday.Start = dtmHolidayDate & " 9:00 AM"
    objHoliday.End = dtmHolidayDate & " 10:00 AM"
    objHoliday.AllDayEvent = True
    objHoliday.ReminderSet = False
    objHoliday.BusyStatus = olOutOfOffice
    objHoliday.Save
Next

Wscript.Echo "Holidays have been added to Outlook calendar"

Open in new window

ran 2nd script ,, asked to select folder .. I select Inbox on mailbox and get error =
(see attachment)


..???
C--Users-m1valencia-Downloads-2015-08-19
You are receiving that error because you are attempting to add calendar appointments to the Inbox folder.  You cannot select Inbox.  That's a folder for mail message items.  You must drill down and select the Calendar folder that you want to add the holidays to.  In my case, when I tested, the folder browser dialog pops us and defaults to my mailbox.  I scroll down to the additional mailbox that contains the calendar I want to update and select the Calendar folder there.

So, this brings up a point I hadn't considered previously.  The shared calendar I am updating belongs to a resource mailbox that I have loaded into my Outlook session, i.e. in the nav pane of Outlook I see both my own mailbox AND the secondary mailbox that has the shared calendar.  As you've probably noticed already, the script's folder browser dialogue only displays folders for mailboxes loaded into the current Outlook session.  It does not show Shared Calendars that you may have access to view/interact with.  I'm not sure if it's possible to programmatically interact with Shared Calendars in this way.  I will investigate.

OM Gang
ASKER CERTIFIED SOLUTION
Avatar of omgang
omgang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks ,,

I can also add more items under "Set objDictionary = CreateObject("Scripting.Dictionary")"  right?


.,,
Below that.

objDictionary.Add "March 11, 2015", "Mom's Birthday"
objDictionary.Add "July 9, 2015", "Anniversary"   '<-----  this isn't a bad idea!
objDictionary.Add "October 12, 2015", "Wife's Birthday"   '<---- this one too!

OM Gang