Does anyone know how I can send an email from visual basic, that will appear in outlook as a calender appointement, then when the user accepts appear in their calender?

Please not I cannot rely on outlook being installed on the host machine, further I would like to specify a sender name

Who is Participating?
KavarConnect With a Mentor Commented:
it used to be a seperate component, (outlook 98 era)  But at this point I think that if you include the CDO dependancy your install will include all of the necessary files...

Dim objSess As Session
Dim objCalFold As Folder ' calendar folder to create appointments in
Dim colAppts As Messages ' appointments collection in calendar folder
Dim objNewAppt As AppointmentItem
Dim colRecips As Recipients ' users to be invited to the meeting

Set objCalFold = objSess.GetDefaultFolder(CdoDefaultFolderCalendar)
Set colAppts = objCalFold.Messages
Set objNewAppt = colAppts.Add ' no parameters when adding appointments
With objNewAppt
   .MeetingStatus = CdoMeeting ' required before calling .Send
   .Importance = CdoHigh
   .Location = "My office"
   .Subject = "Extremely important meeting tomorrow at 9:00 AM!"
   .Text = "We will discuss stock distribution."
   .StartTime = DateAdd("d", 1, DateAdd("h", 9, Date))
   .EndTime = DateAdd("h", 1, .StartTime) ' meeting to last one hour
   Set colRecips = .Recipients ' empty collection of users to invite
End With
With colRecips ' populate collection with invitees
   .Add "John Doe", "" ' can't use parentheses!
   .Add "Joe Blow", ""
   .Resolve ' default to dialog in case of name ambiguities
End With
objNewAppt.Send ' appointment becomes a meeting at this moment
Hi kinton:
> Please not I cannot rely on outlook being installed on the host machine

This makes an already difficult task nearly impossible


You can do it but it will require CDO to be installed, is this acceptable?
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

kintonAuthor Commented:
I should think so.  Is this a large install?  Where can I find it?
kintonAuthor Commented:
Sorry, I have not had a chance to test it yet it would appear Dabas comments are correct and I intend to allocate him the points.  I should have this completed within the next couple of days.
Without Sounding rude, I think I have helped some...
kintonAuthor Commented:
Sorry, I meant Kavar - I copied and pasted the wrong name - please accept my apologies.
kintonAuthor Commented:
This got handed over to someone else in my company and was left for a while, appologies for the delays in replying.

My colleague who has taken on the project is getting the following error on the line below:

runtime error 91
object variable or with block variable not set.

on this line:

Set objCalFold = objSess.GetDefaultFolder(CdoDefaultFolderCalendar)

Seeing as both objCalFold and objSess are defined both myself and my colleague would take a guess that the problem lies with CdoDefaultFolderCalendar, but neither of us know enough about CDO to know for sure.

I'm using Kavar's code as is, and I have referenced CDO 1.2.1

Any help would be much appreciated.
kintonAuthor Commented:
Slight ammendment:

It is ObjSess that hasn't been set.

Is this set in the same way as MAPI?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.