MWsan
MWsan

Reputation: 457

AppointmentItem "From" property

I have this code to create an Outlook appointment from an Excel sheet. It's working fine. But I am using 2 e-mail accounts on Outlook and I don't know how to alternate the meeting host between these accounts. What is the property of AppointmentItem Object, that changes the meeting host?

PS: Isn't "Organizer", I have already tried.

enter image description here


@EDIT:

I was trying to use .SendUsingAccountas suggested by Macro Man, but, still not changing the sender.

My code:

Set oApp = CreateObject("Outlook.Application")
Set ItemAppoint = oApp.CreateItem(1)
ItemAppoint.MeetingStatus = olMeeting

'===============Accounts===============
 Dim Var As Object
 Set Var = ItemAppoint.session.accounts

'======================================

With ItemAppoint
    .SendUsingAccount = Var(2) 'The account that I want to use is the index "2"
    .Subject = "Sub"
    .Body = "text"
    .Display
End With

Upvotes: 1

Views: 3245

Answers (4)

Alejandro
Alejandro

Reputation: 101

I just arrived to this question when searching for a solution to the same problem: in my case the appointment was being created for a different account than desired, and the .SendUsingAccount property was of no help.

I managed to solve this by directly creating the appointment inside the folder I wanted:

Set OutlookApp = CreateObject("Outlook.Application")
Set AppointItem = OutlookApp.GetNamespace("MAPI").Folders("[email protected]").Folders("Calendar").Items.Add(Outlook.OlItemType.olAppointmentItem)

Now the appointment is created for the [email protected] account, and not for the [email protected] account.

Upvotes: 0

This works Well.

Sub Test()
Dim oNamespace As Outlook.Namespace
Dim oCalendarFolder As Outlook.MAPIFolder
Dim oItems As Outlook.items
Dim strEntryID As String
Set oOutlook = CreateObject("Outlook.Application")
Set oNamespace = oOutlook.GetNamespace("MAPI")
For Each i In oNamespace.Folders
    If i.Name = "yourEmailIDhere" Then
        For Each j In i.Folders
            If j.Name = "Calendar" Then
                strEntryID = j.EntryID
            End If
        Next j
    End If
Next i
Set oCalendarFolder = oNamespace.GetFolderFromID(strEntryID)
oItems = oCalendarFolder.items
oMeeting = oItems.Add(Outlook.OlItemType.olAppointmentItem)
oMeeting.Save
oMeeting.Display`

End sub`

Upvotes: 0

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

The AppointmentItem.SendUsingAccount property allows to specify an Account object that represents the account under which the AppointmentItem is to be sent.

What is the property of AppointmentItem Object, that changes the meeting host?

The easiest way is to create an appointment item in the calendar folder which belongs to a particular account. What code do you use for creating appointment items?

The How To: Create a new Outlook Appointment item article explains all possible ways for creating appointment items in Outlook. Try to get the right folder and use the Add method of the Items class. For example:

 items.Add(Outlook.OlItemType.olAppointmentItem)

The GetDefaultFolder method of the Store class returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

Upvotes: 0

SierraOscar
SierraOscar

Reputation: 17647

The .Organizer property is read-only, you're after the .SendUsingAccount property which is read/write

AppointmentItem.SendUsingAccount

More information on the MSDN pages: AppointmentItem.SendUsingAccount Property (Outlook)

Upvotes: 1

Related Questions