Solved

script to insert entries into public calendar

Posted on 2014-09-08
3
179 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
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

803 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