Solved

script to insert entries into public calendar

Posted on 2014-09-08
3
185 Views
Last Modified: 2014-11-06
Experts,

I need to write a script that inserts calendar entries from our Human Resources application into a Vacation Public Calendar that we use. Can anyone provide code snippets on how to do this or point me to any online material that can assist please?

Thanks in advance,
0
Comment
Question by:telliot79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 40325236
Hi, telliot79.

This script will add an entry to a public folder calendar.  I can't be more specific without knowing more about your HR application.

'--> Declare some constants
Const SCRIPT_NAME = "Add Appointments to Vacation Calendar"
' On the next line, edit the path to the calendar
Const CALENDAR_PATH = "Public Folders\All Public Folders\Vacation"

'--> Create some variables
Dim olkApp, olkSes, olkFld, olkApt, intCnt

'--> Connect to Outlook
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
olkSes.Logon olkApp.DefaultProfileName

'--> Connect to the public folder calendar
Set olkFld = OpenOutlookFolder(CALENDAR_PATH)
Select Case TypeName(olkFld)
	Case "Empty","Nothing"
		MsgBox "I could not find the requested folder.  Operation cancelled.", vbCritical+vbOKOnly, SCRIPT_NAME
	Case Else
		'This loop will add an appointment for each entry from your HR application.  I don't know anything about your HR application, so I can't be more specific.
		For Each x In y
			Set olkApt = olkFld.items.add
			With olkApt
				.Subject = ""
				.Start = ""
				.End = ""
				.Save
			End With
			intCnt = intCnt + 1
		Next
		MsgBox "Import complete.  I added " & intCnt & " entries from the HR application.", vbInformation+vbOKOnly, SCRIPT_NAME
End Select

'--> Disconnect from Outlook
olkSes.Logoff

'--Clean-up objects
Set olkApt = Nothing
Set olkFld = Nothing
Set olkSes = Nothing
Set olkApp = Nothing

'--> End processing
WScript.Quit

Function OpenOutlookFolder(strFolderPath)
    Dim arrFolders, varFolder, bolBeyondRoot
    On Error Resume Next
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        Do While Left(strFolderPath, 1) = "\"
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        Loop
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            Select Case bolBeyondRoot
                Case False
                    Set OpenOutlookFolder = olkSes.Folders(varFolder)
                    bolBeyondRoot = True
                Case True
                    Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
            End Select
            If Err.Number <> 0 Then
                Set OpenOutlookFolder = Nothing
                Exit For
            End If
        Next
    End If
    On Error GoTo 0
End Function

Open in new window

0
 

Author Closing Comment

by:telliot79
ID: 40426509
my apologies BlueDevilFan. I should have tended to this sooner.

Thanks for your help.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 40426606
You're welcome.  No worries.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to install and use the NTBackup utility that comes with Windows Server.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data‚Ķ
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question