Solved

Visual Basic - Send an appointment to outlook

Posted on 2004-04-02
10
2,064 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:kinton
  • 6
  • 3
10 Comments
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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
0
 
LVL 2

Author Comment

by:kinton
Comment Utility
Hi,

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

thanks
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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
0
 
LVL 2

Author Comment

by:kinton
Comment Utility
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!
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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
'**********************
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 2

Author Comment

by:kinton
Comment Utility
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?
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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
'**********************
 
0
 
LVL 2

Assisted Solution

by:DaveHavard
DaveHavard earned 200 total points
Comment Utility
Kavar is using late binding so just declare all variables as objects and do not add any references. Add the following to the top of the code:
'*** New line:
Dim myOlApp, myNameSpace, myOutBox, myItem, recip
'*
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myOutBox = myNameSpace.GetDefaultFolder(olFolderOutbox)
Set myItem = myOlApp.CreateItem(olAppointmentItem)
myItem.MeetingStatus = olMeeting
'*** DONT FORGET THE EMAIL ADDRESS HERE - TEST ON YOURS!
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


Dave
0
 
LVL 10

Accepted Solution

by:
Kavar earned 300 total points
Comment Utility
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.
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…

744 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

17 Experts available now in Live!

Get 1:1 Help Now