write to outlook calender with visual basic / vbs

Posted on 2005-05-12
Last Modified: 2013-12-04
Hello Experts
Can somebody help me with and example of how to make an entry in the outlook calendar with visual basic.
Question by:aslandk
    LVL 6

    Expert Comment


    There are two types of Calendar entry in Outlook.  Appointments and Meetings.  Here is an example of creating an Appointment:

    1.  From the Project menu select References.  Tick the box next to the Microsoft Outlook Object Library entry.
    2.  Place a Command Button on your Form named Command1.
    3.  Double click the button in the forms designer which will take you to the code window in the button's Click Event Handler.
    4.  Make your code look like this:

    Private Sub Command1_Click()
    Dim oAppl As New Outlook.Application
    Dim oAppt As Outlook.AppointmentItem
      Set oAppt = oAppl.CreateItem(oAppointmentItem)
      With oAppt
        .Body = "Body"
        .Subject = "Subject"
        .Location = "Location"
        .Duration = 30
        .ReminderMinutesBeforeStart = 10
        .ReminderPlaySound = True
        .Start = CDate("15-05-2005 12:00:00")
      End With
    End Sub

    Run your program and click the command button.  Check your Outlook Calendar for the 15th of May 2005 and your new Appointment entry will be there.

    LVL 33

    Expert Comment

    OL97: Use OLE Automation with Microsoft Outlook 97;en-us;170262

    Adding a New Appointment section

    Author Comment

    Hello TDSnet

    The error "type mismatch in line":

     Set oAppt = oAppl.CreateItem(oAppointmentItem)

    Dont now what is wrong do you?
    LVL 6

    Accepted Solution

    Sorry mate...My bad.  I really should test this stuff before I post it :-)

    Change that line to:

    Set oAppt = oAppl.CreateItem(olAppointmentItem)

    I forgot the "l" in olAppointmentItem


    Author Comment

    Yes i works.....

    THX Jack

    Do you now where to find some examples about adding entry's to other things in outlook(inbox, notes...etc)?
    LVL 6

    Expert Comment

    It all works based on the same basic idea.  If you just have a play around with it you will see what I mean:

    1.  Declare your Outlook.Application object
    2.  Use that to create the item you want to add (MailItem, MeetingItem, ContactItem, AppointmentItem, etc)
         ie.  Outlook.Application.CreateItem(olMailItem)
    3.  Set relevant Properties for that particular item type
         ie.  With myMailItem
                 .Subject = "Hi"
                 .HtmlBody = "Something"
               End With

    If you just play around with that concept then you will find you can create whatever you want.


    Expert Comment

    I am preparing an addin in VB for MS outlook.

    I have written the following code which helps me to add an appointment item to any date of the calendar.
    ' Dim myCalendar As Outlook.MAPIFolder
     Set myCalendar = oNS.GetDefaultFolder(olFolderCalendar)
     Set colCalItems = myCalendar.Items

    Set objAppointment = oApp.CreateItem(olAppointmentItem)
        With objAppointment
            .Body = "Some text"
            .BusyStatus = olBusy
            .Start = #6/10/2005 6:00:00 AM#
            .Duration = 60
            .Subject = "My Appointment"
        End With  
    Now I need to program for two things
    1.  I need to capture the click on the calendar in outlook. ie when the user clicks any particular date of any month or year on the calendar the information should be stored in the calendar object. I must be able to open my add in on clicking any date. Can this be done?
    2.  How do i get the selected date for any particular month or year to be stored in my calendar object. ie If the user clicks 1st May 2005 then my addin should open and i should be able to get 1 st May 2005 to be stored in my calendar object.

    Waiting for ur answer.
    Thanks and regards,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    A short article about a problem I had getting the GPS LocationListener working.
    This is an explanation of a simple data model to help parse a JSON feed
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    758 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

    7 Experts available now in Live!

    Get 1:1 Help Now