我正在尝试在Excel 2007中编写一些VB代码,这些代码会在电子表格中指定的日期自动将会议邀请从Outlook 2007日历发送到Excel电子表格中列出的收件人列表。这很有用,因为我可以通过单击按钮向不同日期的不同人发送数百个会议请求。使用以下代码从我自己的用户帐户发送时,我可以做到这一点:
' 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”中提及
但我无法使用日历约会。
我用“约会”,“会议要求”,“发送电子邮件”等字样搜索了高低,看来你应该可以用'sendusingaccount'进行约会,但这似乎不起作用(它不会失败,只是忽略指令并像以前一样从我自己的用户帐户发送。)
谁能告诉我怎么做? 非常感谢。
答案 0 :(得分:1)
如果您拥有对其他用户邮箱的委派访问权限,请使用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
' i.e.:
' 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!