Sending Calendar Appointment

A

Andy

Hi,

I am simply trying to create an appointment, invite someone and send it. The
code below does most of this. It creates the appointment for 4 days time
between 08:00 and 09:00 I get promted that a program is trying to send an
item so click Yes (once the Yes button appears) but the appointment does not
get sent. It is created in the Calendar though. Any ideas?

SD = Date + 4
SD = DateAdd("h", 8, SD)
ED = DateAdd("h", 1, SD)

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI") ' open the MAPI Namespace

Set olFolder = olNS.GetDefaultFolder(olFolderCalendar)

Set objAppointment = olFolder.Items.Add

With objAppointment
.RequiredAttendees = "(e-mail address removed)"
.Subject = "Event"
.Start = SD
.End = ED
.Recipients.ResolveAll
If .Recipients.ResolveAll Then
.Send
.Close olSave
End If
End With
 
K

Ken Slovak - [MVP - Outlook]

Try setting MeetingStatus. The order in which things are set can also be
important. Usually you set MeetingStatus first and then Location, Subject,
Start, Duration (or End), then recipients. Also add each Recipient object
separately and set the Recipient.Type to whatever you want (required =
olRequired).

See the help in the Outlook VBA in the Object Browser for MeetingStatus to
see a VBA code example.
 
A

Andy

Excellent - Thanks Ken.

One subsidiary question - that promt that a program is trying to send an
item (which you have to click Yes to once the Yes button appears). I
recognise the need for this to protect use from malicious macros but if we
have written the code ourselves and it is running on our own machine - can't
that warning message be suppressed?

Thanks again.
 
K

Ken Slovak - [MVP - Outlook]

In Outlook 2003 and later if you write VBA code in the Outlook VBA project
and derive all of your Outlook objects from the intrinsic Application object
the code is trusted usually.

External code on Outlook 2007 is trusted if the machine has an up-to-date
A-V and has the settings set to allow external trusted code.

Otherwise you have to use one of the workarounds listed at
http://www.outlookcode.com/article.aspx?id=52.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top