Solved

script to insert entries into public calendar

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
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
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

729 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