Outlook
--
Questions
--
Followers
Top Experts
Please advice
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Please see a complete article with example from Microsoft .
https://support.microsoft.com/en-us/kb/313801
Went thru the sample and set VB as specified with no changes in "TODO" area , as recommended in the link (so we can we it work). Â Yet we get this error:
The code is exact as in the link:
Imports System.Reflection
Module Module1
Sub Main()
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Get NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("YourValidProfile", Missing.Value, False, True) ' TODO:
' Get Appointments collection from the Calendar folder.
Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
Dim oItems As Outlook.Items = oCalendar.Items
' TODO: You may want to use Find or Restrict to retrieve the appointment that you prefer.
' ...
' Get the first AppointmentItem.
Dim oAppt As Outlook.AppointmentItem = oItems.GetFirst()
' Display some common properties.
Console.WriteLine(oAppt.Organizer)
Console.WriteLine(oAppt.Subject)
Console.WriteLine(oAppt.Body)
Console.WriteLine(oAppt.Location)
Console.WriteLine(oAppt.Start.ToString())
Console.WriteLine(oAppt.End.ToString())
' Display.
'oAppt.Display(true)
' Log off.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oAppt = Nothing
End Sub
End Module
Dim oAppt As Outlook.AppointmentItem = oItems.GetFirst()






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlo

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
so it can open a specific folder we need. Â Unfortunately to no avail.
Please help on opening in VB specific Calendar folder.
(the above line is from the coe we are working with below)
Imports System.Reflection
Module Module1
Sub Main()
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Get NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("YourValidProfile", Missing.Value, False, True) ' TODO:
' Get Appointments collection from the Calendar folder.
Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
Dim oItems As Outlook.Items = oCalendar.Items
' TODO: You may want to use Find or Restrict to retrieve the appointment that you prefer.
' ...
' Get the first AppointmentItem.
Dim oAppt As Outlook.AppointmentItem = oItems.GetFirst()
' Display some common properties.
Console.WriteLine(oAppt.Organizer)
Console.WriteLine(oAppt.Subject)
Console.WriteLine(oAppt.Body)
Console.WriteLine(oAppt.Location)
Console.WriteLine(oAppt.Start.ToString())
Console.WriteLine(oAppt.End.ToString())
' Display.
'oAppt.Display(true)
' Log off.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oAppt = Nothing
End Sub
End Module

Here the code:
Sub Main()
'Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
'Get NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("RT.pst", Missing.Value, False, True)
Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.Folder)
Dim oItems As Outlook.Items = oCalendar.Items
Dim folders As Outlook.Folders = oApp.Session.Folders
For Each folder As Outlook.Folder In folders
'Replace the calendar name with your calendar name
Dim objModule As Outlook.CalendarModule = folder.GetExplorer().NavigationPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar)
Dim objGroup As Outlook.NavigationGroup = objModule.NavigationGroups.GetDefaultNavigationGroup(Outlook.OlGroupType.olMyFoldersGroup)
For Each navfolder As Outlook.NavigationFolder In objGroup.NavigationFolders
Console.WriteLine(navfolder.Folder.Name)
Debug.WriteLine(navfolder.DisplayName)
'TODO:Replace the calendar name with your calendar name
If navfolder.Folder.Name = "Calendar" Then
oItems = navfolder.Folder.Items
Exit For
End If
Next
Next
'Display.
'oAppt.Display(true)
'Log off.
oNS.Logoff()
'Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oAppt = Nothing
End Sub
Where are going wrong?
Also please give your calendar name appropriately, by default all calendars have name as 'Calendar' so try to give your iCloud calendar a different name and try to use the same in the code below.
1> First error: Expression is of type Outlook.Folders, which is not a collection type.
Please add reference to Microsoft.Office.InterOp.Outlook assembly to your project.
Right click your project in solution explorer and click on add reference and select the above mentioned assembly
And import following namespace at the top.
Imports Microsoft.Office.Interop
2> Second error: oAppt is not declaredRemove oAppt = nothing at the last line, not required since not used
3> Please use modified code below.Imports System.Reflection
Imports Microsoft.Office.Interop
Sub Main()
'Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
'Get NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("RT.pst", Missing.Value, False, True)
Dim oItems As Outlook.Items
Dim myfolders As Outlook.Folders = oApp.Session.Folders
For Each myfolder As Outlook.Folder In myfolders
Dim calendarfound As Boolean = False
'Replace the calendar name with your calendar name
Dim objModule As Outlook.CalendarModule = myfolder.GetExplorer().NavigationPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar)
Dim objGroup As Outlook.NavigationGroup = objModule.NavigationGroups.GetDefaultNavigationGroup(Outlook.OlGroupType.olMyFoldersGroup)
For Each navfolder As Outlook.NavigationFolder In objGroup.NavigationFolders
Console.WriteLine(navfolder.Folder.Name)
Debug.WriteLine(navfolder.DisplayName)
'TODO:Replace the calendar name with your calendar name
If navfolder.Folder.Name = "Calendar" Then
oItems = navfolder.Folder.Items
calendarfound = True
Exit For
End If
Next
If calendarfound Then Exit For
Next
'Display.
'oAppt.Display(true)
'Log off.
oNS.Logoff()
'Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
End Sub






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
2> For correct calendar name, just iterate through once to see what all calendar names are getting printed and then based on that we can find out which one is yours.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Leave that if condition as it is, and first check all the calendar names getting printed in the debug output window and based on that change the if condition later on.
(and we added the reference instructed)






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
(sorry couldn't continue last night. Â Even though desperately to finish this the computer acted up no internet)
Ok, we downloaded your sample and open the 'OutLookCalendarTest2012.sl
The curious thing is our project has  'Microsoft.Office.Interop.O
Neverthess, see your sample loaded; still the blue underline:
There has to be something we are missing (sorry that we are not too tech in VB)

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
But anyway, I wonder how in first comment, you were able to compile and open the default calendar because that also used the same outlook API's and DLL being used. Has anything changed when since then when you were able to log on and open the default calendar which did not have any appointments?
The assemblies that we are referring should be inside this folder under Office 12 or Office 14 or Office 15 folder.
The below is an example, in my case it is installed in F drive, please check in your computer based on where you have installed visual studio.
F:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\
PIA assemblies for Office 2010






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Can you check in your visual studio installation folder whether you have following folder?
If you do not have the PIA assemblies as mentioned in comment above, then please install
Then please perform a compile and post if you get any compilation errors.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Did your code worked at your computer?
Did your code open a specific calendar?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
The updated modified code is found  in ID: 41391159 (you can download from there).
The Error are found in ID: 41391583.
Thanx! (Hope u can find what we haven't)

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
PIA assemblies






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Installing!
Installed it, the installation just showed a windows (see below) and disappear.

went into "add reference", went to folder "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Office14"

no luck.
Can you send a code or zipped file with the project? We must doing something wrong

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Ok thanx!






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Outlook
--
Questions
--
Followers
Top Experts
Microsoft Outlook is a personal information manager from Microsoft, available as a part of the Microsoft Office suite. Although often used mainly as an email application, it also includes a calendar, task manager, contact manager, note-taker, journal, and web browser.



