More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

share code 23-May-2019 09:48

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

Code level: beginner    Code area: Basic Outlook Printer Friendly Version
Title: Add appointment to other user's Calendar
Description: You can use the Namespace.GetSharedDefaultFolder method to access the Calendar folder in another Exchange mailbox. Keep in mind that you might not have permission to even see that folder, or you might have only read access.
Date: 13-Dec-2002  01:08
Code level: beginner
Code area: Basic Outlook
Posted by: Sue Mosher
This message is displayed as VB.NET
 Sub CreateOtherUserAppointment()
    Dim objApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Dim objDummy As Outlook.MailItem
    Dim objRecip As Outlook.Recipient
    Dim objAppt As Outlook.AppointmentItem
    Dim strMsg As String
    Dim strName As String
    On Error Resume Next
    
    ' ### name of person whose Calendar you want to use ###
    strName = "FlaviusJ"
    
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
    Set objDummy = objApp.CreateItem(olMailItem)
    Set objRecip = objDummy.Recipients.Add(strName)
    objRecip.Resolve
    If objRecip.Resolved Then
        On Error Resume Next
        Set objFolder = _
          objNS.GetSharedDefaultFolder(objRecip, _
            olFolderCalendar)
        If Not objFolder Is Nothing Then
            Set objAppt = objFolder.Items.Add
            If Not objAppt Is Nothing Then
                With objAppt
                    .Subject = "Test Appointment"
                    .Start = Date + 14
                    .AllDayEvent = True
                    .Save
                End With
            End If
        End If
    Else
        MsgBox "Could not find " & Chr(34) & strName & Chr(34), , _
               "User not found"
    End If

    Set objApp = Nothing
    Set objNS = Nothing
    Set objFolder = Nothing
    Set objDummy = Nothing
    Set objRecip = Nothing
    Set objAppt = Nothing
End Sub
All 100comments
Page [ 1 2 3 4 5 6 7 8 9 10 Next >>  
  22-Mar-2003  19:07   
How can I modify this to run from another program?For example how could I go about running this from cscript filename.vbs? I have tried and tried to no avail. I added a Const olFolderCalendar = 9 at the top of the script, but the appointment does not appear in Outlook.



What am I missing? I am trying to run this from Windows 2000.



Thanks!
  07-May-2003  17:52   
If you are running this in VBScript, you must remove all the data typing (e.g. "As String") and either declare the Outlook constants (e.g. olFolderCalendar) or use their literal values only. You can look up the values in the object browser.
  08-May-2003  11:41   
Hi Sue, thanks a lot for posting your code sample re. using Namespace.GetSharedDefaultFolder method to access the Calendar folder in another Exchange mailbox. What I am trying to do is simply look in the Calendar folder of another Exchange user and see what meetings & appointments they have scheduled and the start and end times for these meetings & appointments. I can't seem to rework your code sample to accomplish this. Could you please make any suggestions & code modifications on how I can do this. Thanks very much in advance!
  30-Jun-2003  07:37   
Peter, take a look at the Namespace.GetSharedDefaultFolder method. Once you return the MAPIFolder for the shared mailbox, you can use a For Each ... Next loop to loop through all the items in the folder.
  24-Mar-2004  17:57   
An alternative way to get the necessary Recipient is to use the Application.CreateRecipient method with a unique name or address. As long as you don't use Recipient.Resolve, this technique should not trigger an Outlook security prompt.
  23-Apr-2004  12:06   
For an equivalent sample in VB.NET, see http://www.outlookcode.com/codedetail.aspx?id=405
  08-Jul-2004  23:47   
If I use this code on my PC, works fine, but asks security prompt.
Can you tell me why? and what is the solution for this
  20-Jul-2004  10:18   
The "object model guard" is explained at http://www.outlookcode.com/d/sec.htm . See if this variation avoids the prompt by not attempting the resolve the Recipient:

    Set objRecip = olApp.CreateRecipient(strName)
    On Error Resume Next
    Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
  10-Aug-2004  11:46   
I am trying to use this to post to a public calendar rather than that of an idividual. What changes should I make to accomplish this?
  10-Aug-2004  16:50   
You would replace this statement:

        Set objFolder = _
          objNS.GetSharedDefaultFolder(objRecip, _
            olFolderCalendar)

with a statement that sets the objFolder variable to the desired public folder. To get a non-default folder, you need to walk the folder hierarchy using the Folders collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm
 
Page [ 1 2 3 4 5 6 7 8 9 10 Next >>