Solved

Script to delete/create outlook appointment

Posted on 2014-09-12
1
340 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 48

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!

Join & Write a Comment

Suggested Solutions

My experience with Windows 10 over a one year period and suggestions for smooth operation
Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
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…
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now