May 10th, 2007, 05:34 AM
#1
Thread Starter
Hyperactive Member
[2005] Add Appointment To Outlook Calendar
Hello,
I want to add an appointment to the users Outlook Calendar when I pass in a date.
To do this, I'm calling the following code :
Code:
Public Sub AddHolToOutlook(ByVal m_Start As Date)
' Start Outlook.
' If it is already running, you'll use the same instance...
Dim OlAPP = CreateObject("Outlook.Application")
' Logon. Doesn't hurt if you are already running and logged on...
Dim olNs
olNs = OlAPP.GetNamespace("MAPI")
olNs.LogOn()
' Create a new appointment.
Dim olAppt = OlAPP.Createitem(1)
' Setup other appointment information...
With olAppt
.AllDayEvent = True
.Start = m_Start
.Subject = "Holiday"
.ReminderSet = False
End With
' Save Appointment...
olAppt.Save()
' Clean Up
olAppt = Nothing
olNs = Nothing
OlAPP = Nothing
End Sub
However, I get a message saying "Cannot create ActiveX component."
I've no idea what this means, or whether my code is anywhere near correct.
Can anyone shed any light on this please ?
Last edited by Jonny1409; May 10th, 2007 at 11:00 AM .
May 10th, 2007, 10:57 AM
#2
Re: [2005] Add Appointment To Outlook Calendar
Code:
Dim OlAPP = As Object = CreateObject("Outlook.Application")
'...
Dim olAppt As Object = OlAPP.CreateItem(1)
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 10th, 2007, 11:01 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] Add Appointment To Outlook Calendar
Hi RobDog888,
Thanks for replying.
I've tried this, but unfortunately it doesn't work.
I still get the same error on the line :
Code:
Dim OlAPP As Object = CreateObject("Outlook.Application")
May 10th, 2007, 11:03 AM
#4
Re: [2005] Add Appointment To Outlook Calendar
Are you using early or late binding? (Added a reference to Outlook or not).
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 11th, 2007, 01:58 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] Add Appointment To Outlook Calendar
I've added a reference to Microsoft Outlook through the com tab if this helps?
May 11th, 2007, 02:05 AM
#6
Re: [2005] Add Appointment To Outlook Calendar
Reference to - Microsoft Outlook xx.0 Object Library? Also, added the imports declaration?
Code:
Option Explicit On
Option Strict On
Imports Microsoft.Office.Interop
Public Class Form1
Private moApp As Outlook.Application
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
moApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
End Sub
End Class
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 11th, 2007, 02:31 AM
#7
Thread Starter
Hyperactive Member
Re: [2005] Add Appointment To Outlook Calendar
Yeah Microsoft Outlook 11.0 Object Library.
I hadn't had the imports statement in, but when I've added it I get a green line under it, and the message says :
"Namespace or type specified in the imports microsoft.office.interop doesn't contain any public member or cannot be found....."
May 11th, 2007, 02:33 AM
#8
Re: [2005] Add Appointment To Outlook Calendar
Thats usually because you may have added "Microsoft Office 11.0 Object Library" instead of "Microsoft Outlook 11.0 Object Lirary"
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 11th, 2007, 02:43 AM
#9
Thread Starter
Hyperactive Member
Re: [2005] Add Appointment To Outlook Calendar
Hi RobDog,
Cheers for your continued help with this - I've removed the reference and added it again. (The screenshot shows the exact file)
It actually adds 2 things to my references :
Microsoft.Office.Core
Outlook
Yet the green line above still shows.
Attached Images
May 11th, 2007, 02:59 AM
#10
Re: [2005] Add Appointment To Outlook Calendar
Should be "Imports Microsoft.Office.Interop" not .Core"
If intellisense doesnt popup with .Interop then you may not have the PIAs installed. See the link in my signature for the "Primary Interop Assemblies"
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 11th, 2007, 03:23 AM
#11
Thread Starter
Hyperactive Member
Re: [2005] Add Appointment To Outlook Calendar
Thanks RobDog,
I've now installed those, and checked control panel to make sure they are there. (And they are)
I've removed the reference and added it again.
The green line is now gone, and interop also shows in the intellisense but I still get the error when using the code you supplied.
May 11th, 2007, 11:16 AM
#12
Re: [2005] Add Appointment To Outlook Calendar
Hmm, the code from #6 doesnt work for you then maybe something else is the issue as its basic clean code that works in 2003/2005.
Do you have all your Windows/Office Updates installed? Any AV programs? Any issues at all? Try creating a new blank solution and place my code behind a form. Test.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width