Solved

script to insert entries into public calendar

Posted on 2014-09-08
3
176 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
Comment Utility
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
Comment Utility
my apologies BlueDevilFan. I should have tended to this sooner.

Thanks for your help.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're welcome.  No worries.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
how to add IIS SMTP to handle application/Scanner relays into office 365.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now