使用Excel数据创建Outlook会议请求
我正在编写创建Outlook会议请求的代码,以发送给受邀者列表。使用Excel数据创建Outlook会议请求,excel,vba,outlook,Excel,Vba,Outlook,我正在编写创建Outlook会议请求的代码,以发送给受邀者列表。 我在日历中看到会议请求,但无法发送。 我怎样才能把它寄出去 子添加约会() '创建Outlook会话 设置myOutlook=CreateObject(“Outlook.Application”) '从第2行开始 r=2 直到修剪(单元格(r,1)。值)=“” '创建AppointmentItem 设置myApt=myOutlook.CreateItem(1) '设置约会属性 myApt.Subject=单元格(r,1).Valu
我在日历中看到会议请求,但无法发送。
我怎样才能把它寄出去
子添加约会()
'创建Outlook会话
设置myOutlook=CreateObject(“Outlook.Application”)
'从第2行开始
r=2
直到修剪(单元格(r,1)。值)=“”
'创建AppointmentItem
设置myApt=myOutlook.CreateItem(1)
'设置约会属性
myApt.Subject=单元格(r,1).Value
myApt.Location=单元格(r,2).Value
myApt.Start=单元格(r,3).Value
myApt.Duration=单元格(r,4).值
myApt.Recipients.Add单元格(r,8).Value
myApt.MeetingStatus=olMeeting
myApt.ReminderMinutesBeforeStart=88
myApt.Recipients.ResolveAll
myApt.AllDayEvent=全天
'如果未指定忙状态,则默认为2(忙)
如果修剪(单元格(r,5).Value)=“”,则
myApt.BusyStatus=2
其他的
myApt.BusyStatus=单元格(r,5).值
如果结束
如果单元格(r,6).值>0,则
myApt.rementerset=True
myApt.rementerMinutesBeforestart=单元格(r,6).值
其他的
myApt.rementerset=False
如果结束
myApt.Body=单元格(r,7).值
myApt.保存
r=r+1
myApt.发送
环
端接头
如果没有值的示例行,则很难调试此代码。所以,我们只会相信你的话,它是有效的。但我确实修改了一点代码
- 您的代码中有两次提醒项。我删除了第一个,因为它看起来依赖于行数据
- 调用ResolveAll方法,但不检查收件人是否已解析。如果它们是电子邮件地址,我就不麻烦了
- 有一个早期和后期绑定引用的混合。例如,您使用1而不是olAppointmentItem,但稍后使用olMeeting而不是1
- AllDayEvent属性采用布尔值,但由于您尚未声明任何变量,我们无法判断AllDay的含义。我将其转换为从第I列读取。还要注意,如果将AllDayEvent设置为True,则不需要设置持续时间
Option Explicit
Sub AddAppointments()
Dim myoutlook As Object ' Outlook.Application
Dim r As Long
Dim myapt As Object ' Outlook.AppointmentItem
' late bound constants
Const olAppointmentItem = 1
Const olBusy = 2
Const olMeeting = 1
' Create the Outlook session
Set myoutlook = CreateObject("Outlook.Application")
' Start at row 2
r = 2
Do Until Trim$(Cells(r, 1).value) = ""
' Create the AppointmentItem
Set myapt = myoutlook.CreateItem(olAppointmentItem)
' Set the appointment properties
With myapt
.Subject = Cells(r, 1).value
.Location = Cells(r, 2).value
.Start = Cells(r, 3).value
.Duration = Cells(r, 4).value
.Recipients.Add Cells(r, 8).value
.MeetingStatus = olMeeting
' not necessary if recipients are email addresses
' myapt.Recipients.ResolveAll
.AllDayEvent = Cells(r, 9).value
' If Busy Status is not specified, default to 2 (Busy)
If Len(Trim$(Cells(r, 5).value)) = 0 Then
.BusyStatus = olBusy
Else
.BusyStatus = Cells(r, 5).value
End If
If Cells(r, 6).value > 0 Then
.ReminderSet = True
.ReminderMinutesBeforeStart = Cells(r, 6).value
Else
.ReminderSet = False
End If
.Body = Cells(r, 7).value
.Save
r = r + 1
.Send
End With
Loop
End Sub
单元格中的示例输入值(包括标题行):
- 我的会议
- 我的桌子
- C2:2011年11月25日下午13:30:00
- D2:30
- E2:2
- F2:30
- G2:我们开个会吧李>
- H2:-电子邮件地址-
- I2:错误
- 您的代码中有两次提醒项。我删除了第一个,因为它看起来依赖于行数据
- 调用ResolveAll方法,但不检查收件人是否已解析。如果它们是电子邮件地址,我就不麻烦了
- 有一个早期和后期绑定引用的混合。例如,您使用1而不是olAppointmentItem,但稍后使用olMeeting而不是1
- AllDayEvent属性采用布尔值,但由于您尚未声明任何变量,我们无法判断AllDay的含义。我将其转换为从第I列读取。还要注意,如果将AllDayEvent设置为True,则不需要设置持续时间
- 如果没有一行示例值,则很难调试此代码。所以,我们只会相信你的话,它是有效的。但我确实修改了一点代码
Option Explicit
Sub AddAppointments()
Dim myoutlook As Object ' Outlook.Application
Dim r As Long
Dim myapt As Object ' Outlook.AppointmentItem
' late bound constants
Const olAppointmentItem = 1
Const olBusy = 2
Const olMeeting = 1
' Create the Outlook session
Set myoutlook = CreateObject("Outlook.Application")
' Start at row 2
r = 2
Do Until Trim$(Cells(r, 1).value) = ""
' Create the AppointmentItem
Set myapt = myoutlook.CreateItem(olAppointmentItem)
' Set the appointment properties
With myapt
.Subject = Cells(r, 1).value
.Location = Cells(r, 2).value
.Start = Cells(r, 3).value
.Duration = Cells(r, 4).value
.Recipients.Add Cells(r, 8).value
.MeetingStatus = olMeeting
' not necessary if recipients are email addresses
' myapt.Recipients.ResolveAll
.AllDayEvent = Cells(r, 9).value
' If Busy Status is not specified, default to 2 (Busy)
If Len(Trim$(Cells(r, 5).value)) = 0 Then
.BusyStatus = olBusy
Else
.BusyStatus = Cells(r, 5).value
End If
If Cells(r, 6).value > 0 Then
.ReminderSet = True
.ReminderMinutesBeforeStart = Cells(r, 6).value
Else
.ReminderSet = False
End If
.Body = Cells(r, 7).value
.Save
r = r + 1
.Send
End With
Loop
End Sub
单元格中的示例输入值(包括标题行):
- 我的会议
- 我的桌子
- C2:2011年11月25日下午13:30:00
- D2:30
- E2:2
- F2:30
- G2:我们开个会吧李>
- H2:-电子邮件地址-
- I2:错误
- 它对我有用
请记住有多行,如
.Recipients.Add Cells(r, 8).value
添加更多收件人。
因为在一个单元格中写入多个由“;”分隔的地址会导致发送约会时出错
或使用
.Recipients.ResolveAll
这对我有用
请记住有多行,如
.Recipients.Add Cells(r, 8).value
添加更多收件人。
因为在一个单元格中写入多个由“;”分隔的地址会导致发送约会时出错
或使用
.Recipients.ResolveAll
运行代码时会发生什么?任何错误、Outlook安全警告等?我没有收到任何错误。问题是会议请求不是出于了望而发送的。您是否检查了所需的参考资料?(如果没有,我想您会有错误)您是否在代码的开头(在第一个子代码之前)添加了
选项Explicit
?如果您仍然没有引发任何错误,请尝试仅使用硬编码值执行部分代码,特别是不起作用的代码(例如发送约会)。我已尝试使用Option Explicit、Compiler error.和istead of myApt.Send,我已使用myApt.Display,显示会议请求…………唯一的问题是,当我使用myApt.Send时,它不会为此会议请求发送邮件运行代码时会发生什么?任何错误、Outlook安全警告等?我没有收到任何错误。问题是会议请求不是出于了望而发送的。您是否检查了所需的参考资料?(如果没有,我想您会有错误)您是否在代码的开头(在第一个子代码之前)添加了选项Explicit
?如果您仍然没有引发任何错误,请尝试仅使用硬编码值执行部分代码,特别是不起作用的代码(例如发送约会)。我已尝试使用Option Explicit、Compiler error.和istead of myApt.Send,我已使用myApt.Display,会议请求的显示出现了…………唯一的问题是,当我使用myApt.Send时,它并没有为此发送邮件