Solved

Script to delete/create outlook appointment

Posted on 2014-09-12
1
364 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 49

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

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

If you don't know how to downgrade, my instructions below should be helpful.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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…
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…

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