Solved

Script to delete/create outlook appointment

Posted on 2014-09-12
1
369 Views
Last Modified: 2014-09-22
Hey

I need a script (vbscript) to delete and create a specific calendar appointment i Outlook 2010.

Thanks in advance.

Mike
0
Comment
Question by:mikeydk
1 Comment
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40318920
HI,

pls try  (cannot test in VBS not Home) but in VBa it runs

to create

Const olAppointmentItem = 1

Set objOutlook = CreateObject("Outlook.Application")
Set objAppointment = objOutlook.CreateItem(olAppointmentItem)

objAppointment.Start = #4/11/2014 10:00 AM#
objAppointment.Duration = 120
objAppointment.Subject = "My Subject"
objAppointment.Body = "my Body."
objAppointment.Location = "tbd"
objAppointment.ReminderMinutesBeforeStart = 30
objAppointment.ReminderSet = True
 
objAppointment.Save
' to delete

DeleteAppointments "My Subject"


Sub DeleteAppointments(strSubj)
Const olAppointmentItem = 1
Const olFolderCalendar = 9
Const olAppointment = 26
Set objOutlook = CreateObject("Outlook.Application")
Set objAppointment = objOutlook.CreateItem(olAppointmentItem)
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFolderCalendar)

 
For Each obj In objFolder.Items
  If obj.Class = olAppointment Then
    Set objAppointment = obj
    If InStr(objAppointment.Subject, strSubj) > 0 Then
      intAnswer = MsgBox("Appointment found:-" & vbCrLf & vbCrLf _
           & "Date/time: " & Format(objAppointment.Start, "dd/mm/yyyy hh:nn") _
           & " (" & objAppointment.Duration & "mins)" & Space(10) & vbCrLf _
           & "Subject: " & objAppointment.Subject & Space(10) & vbCrLf _
           & "Location: " & objAppointment.Location & Space(10) & vbCrLf & vbCrLf _
           & "Delete this appointment?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete Appointment?")
      If intAnswer = vbYes Then objAppointment.Delete
    End If
  End If
Next 

Set objOutlook = Nothing
Set objNameSpace = Nothing
Set objFolder = Nothing
Set obj = Nothing
Set objAppointment = Nothing

Exit Sub

Open in new window

Regards
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you don't know how to downgrade, my instructions below should be helpful.
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

828 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