none
VB.NET and Outlook Calendars RRS feed

  • Question

  • Hi all, I've found alot of code out there very helpful to being able to write to local Outlook calendar as well as another users calendar in the domain.  What I'm running into, is the machine I am attempting to run from is on one domain, but my outlook is ran off of another.  I log onto machine as domain1\user and outlook as domain2\user

    My user has access to write to the other calendars that I need it to, but I can't figure out how to go across the domain to access it - or maybe i'm completely off track.

    Imports System.Data.SqlClient
    Imports Outlook = Microsoft.Office.Interop.Outlook
    Imports System.Reflection
    Imports System
    
    
    Module Module1
      
    
    
        Public Sub CreateOtherUserAppointment()
            Dim objolApp As New Outlook.Application
            Dim objNS As Outlook.NameSpace
            Dim objRecip As Outlook.Recipient
            Dim objFolder As Outlook.MAPIFolder
            Dim objAppt As Outlook.AppointmentItem
            Dim strName As String
    
            ' ### name or email address of person whose Calendar you want to use ###
            strName = "domain2\jdf7878"
    
            objNS = objolApp.GetNamespace("MAPI")
            Try
                objRecip = objNS.CreateRecipient(strName)
                objRecip.Resolve()
    
                If objRecip.Resolved Then
                    objFolder = objNS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderCalendar)
                    objAppt = objFolder.Items.Add
                    With objAppt
                        .Start = DateAdd("d", 1, System.DateTime.Now)
                        .Duration = 30
                        .Subject = "Test at " & FormatDateTime(System.DateTime.Now, DateFormat.ShortTime)
                        .Save()
                    End With
                End If
            Catch ex As System.Runtime.InteropServices.COMException
                Select Case ex.ErrorCode
                    Case -2147467260    ' User responded NO to security prompt
                        MessageBox.Show("It won't work unless you say Yes to the security prompt.")
                    Case -1767636707    ' store not available to GetSharedDefaultFolder
                        MessageBox.Show("Information store for " & objRecip.Name & " not available.")
                    Case -1664876273    ' no permissions for folder
                        MessageBox.Show("You do not have permission to view the folder.")
                    Case -632274939     ' read-only permission, cannot write
                        MessageBox.Show("You do not have permission to create a new item in the folder.")
                    Case Else
                        MessageBox.Show("COMException - " & ex.ErrorCode)
                End Select
            Catch ex As Exception
                MessageBox.Show(ex.Message, ex.ToString)
            Finally
                objFolder = Nothing
                objAppt = Nothing
                objRecip = Nothing
            End Try
    
            objNS = Nothing
            objolApp = Nothing
        End Sub
    End Module
    
    Any help will be greatly appreciated
    Monday, August 17, 2015 6:19 PM

All replies

  • Hello,

    If another user allows to create new entries on the calendar (write permissions) you can create new entries. Do you get any errors in the code?

    Monday, August 17, 2015 6:30 PM
  • Did you try to add the second user's mailbox to your profile?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, August 17, 2015 7:53 PM