如何在Outlook2007中使用VB代码发送一系列使用sendonbehalfof作为委托的会议邀请

我试图在Excel 2007中编写一些VB代码,这些代码将自动从Outlook 2007日历中发送会议邀请到Excel电子表格中列出的收件人列表,在电子表格中指定的date。 这很有用,因为我可以通过点击一个button向不同date的不同人发送数百个会议请求。 使用以下代码从我自己的用户帐户发送时,我可以做到这一点:

' Create the Outlook session Set myoutlook = CreateObject("Outlook.Application") ' Create the AppointmentItem Set myapt = myoutlook.CreateItem(olAppointmentItem) ' Set the appointment properties With myapt .Subject = " Assessment Centre " .Location = "conference room A" .Start = Cells(5, 24 + j) & " 17:00:00 PM" .Duration = 120 .Recipients.Add Cells(i, 1).Value .MeetingStatus = olMeeting ' not necessary if recipients are email addresses 'myapt.Recipients.ResolveAll .AllDayEvent = "False" .BusyStatus = "2" .ReminderSet = False .Body = L1 & vbCrLf & vbCrLf & L2 & vbCrLf & vbCrLf & L3 & vbCrLf & vbCrLf & L4 .Save .send End With 

但是现在我想从一个虚拟的用户帐户(我是一个委托人)使用类似'sendonbehalfof'的虚拟用户帐户发送会议请求,以便虚拟日历存储所有会议邀请,其他代表也可以使用同一个虚拟帐户用户帐号。 使用以下代码发送电子邮件时可以正常工作:

 Set oApp = CreateObject("Outlook.Application") Set oMail = oApp.CreateItem(0) With oMail .To = " John.Smith@John_Smith.com " .Subject = "Subject" .Body = "Body" .SentOnBehalfOfName = "Fred.bloggs@fred_blogs.com" .send End With 

电子邮件会从'我代表Fred Bloggs'

但我不能让它与日历约会。

我用“预约”,“会议请求”,“sendonbehalfof”等词来search高低,似乎你应该可以这样做与'sendusingaccount'的约会,但这似乎并没有工作(它doesn不会失败,只是忽略指令,并像以前一样从我自己的用户帐户发送)。

谁能告诉我如何做到这一点? 非常感谢。

如果您有委派访问另一个用户的邮箱,使用GetSharedDefaultFolder获取用户的共享日历的引用,然后使用Folders.Items.Add将会议添加到他们的日历。

例如:

 Dim fldr As Outlook.Folder Dim appt As Outlook.AppointmentItem Set fldr = Session.GetSharedDefaultFolder(_ Outlook.CreateRecipient("Fred.bloggs@fred_blogs.com"), _ olFolderCalendar) Set appt = fldr.Items.Add ' set up your appointment here ' ie: ' With appt ' .Start = Cells(5, 24 + j) & " 17:00:00 PM" ' .Duration = 120 ' End With ' make sure you call the appt.Save method to save the appt! 

改编自http://www.outlookcode.com/codedetail.aspx?id=43