?
Solved

script to insert entries into public calendar

Posted on 2014-09-08
3
Medium Priority
?
188 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 2000 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This video discusses moving either the default database or any database to a new volume.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

770 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