Link to home
Start Free TrialLog in
Avatar of kinton
kinton

asked on

Visual Basic - Send an appointment to outlook

Hi,

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?

thanks
Avatar of Kavar
Kavar

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olAppointmentItem)
set recip=myItem.Recipients.Add "MYemail@company.com"
recip.Type = olRequired
myItem.Subject="Come To My Meeting"
myItem.Start = #4/2/2004 1:30:00 PM#
myItem.Duration = 90
Set myResourceAttendee =myItem.Recipients.Add("Conference Room B")
myResourceAttendee.Type = olResource
myItem.Send
Avatar of kinton

ASKER

Hi,

Could you tell me what your variables are here, and where applicable your components or references?

thanks
olAppointmentItem=1
olRequired=1
olResource=3

Don't include Any references if you want this to be portable to other versions of Outlook, if this is just for on machine and the outlook version wont change, add the Microsoft Outlook Object Model
Avatar of kinton

ASKER

Sorry, I think I am misunderstanding something!  What variables do I need to declare and what should I declare them as, the code seems to be running fine but no appointment is appearing!
ahhh yes if you want to send to someone else there is one more step, use this code ...

'****************
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myOutBox = myNameSpace.GetDefaultFolder(olFolderOutbox)
Set myitem = myOlApp.CreateItem(olAppointmentItem)
myitem.MeetingStatus = olMeeting
Set recip = myitem.Recipients.Add("<emailAddressHere>")
recip.Type = olRequired
recip.Resolve
myitem.Subject = "Come To My Meeting"
myitem.Start = #4/2/2004 1:30:00 PM#
myitem.Duration = 90
myitem.Send
Set myitem = Nothing
'**********************
Avatar of kinton

ASKER

I can't even get it to appear my self!  I think I must be declaring the variables wrong, can you give me the correct declaration statement?
Comment from Kavar
Date: 04/02/2004 08:47AM CST
 Your Comment  


Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olAppointmentItem)
set recip=myItem.Recipients.Add "MYemail@company.com"
recip.Type = olRequired
myItem.Subject="Come To My Meeting"
myItem.Start = #4/2/2004 1:30:00 PM#
myItem.Duration = 90
Set myResourceAttendee =myItem.Recipients.Add("Conference Room B")
myResourceAttendee.Type = olResource
myItem.Send
 
Comment from kinton
Date: 04/02/2004 08:50AM CST
 Author Comment  


Hi,

Could you tell me what your variables are here, and where applicable your components or references?

thanks
 
Comment from Kavar
Date: 04/02/2004 08:56AM CST
 Your Comment  


olAppointmentItem=1
olRequired=1
olResource=3

Don't include Any references if you want this to be portable to other versions of Outlook, if this is just for on machine and the outlook version wont change, add the Microsoft Outlook Object Model
 
Comment from kinton
Date: 04/02/2004 09:08AM CST
 Author Comment  


Sorry, I think I am misunderstanding something!  What variables do I need to declare and what should I declare them as, the code seems to be running fine but no appointment is appearing!
 
Comment from Kavar
Date: 04/02/2004 09:30AM CST
 Your Comment  


ahhh yes if you want to send to someone else there is one more step, use this code ...

'****************
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myOutBox = myNameSpace.GetDefaultFolder(4)
Set myitem = myOlApp.CreateItem(1)
myitem.MeetingStatus = 1
Set recip = myitem.Recipients.Add("<emailAddressHere>")
recip.Type = 1
recip.Resolve
myitem.Subject = "Come To My Meeting"
myitem.Start = #4/2/2004 1:30:00 PM#
myitem.Duration = 90
myitem.Send
Set myitem = Nothing
'**********************
 
SOLUTION
Avatar of DaveHavard
DaveHavard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the reason why nothing was happening was because he had not included  the outlook object model so he didn't support named constants, my last post has the correct values.

The only time in vb declaring type variants is required is when option explicit is used, if that had been turned on the script would not have run at all.