信息: MS Office 2010
**Problem(s)**多个 Outlook 配置文件和多个日历,并且重复相同的日期-我只希望唯一
来自: Excel 2010
至: Outlook 2010
题 :
我想创建一个从 Excel 运行到 Outlook 的 VBA。我想根据我工作表中的日期列创建约会(如果证明更合适,则执行任务)。
核心问题是:
- 我有 3 个不同的个人资料,我只希望 appointments/tasks 显示在 1 个个人资料中(管理员)。
- 我有不同的日历,我希望约会为默认日历。
- 我想为 appointment/task 添加类别,我有 10,000 行数据,日期重复很多,我只想要唯一的日期。
- 我不想事先创建 appointments/tasks(如果可能)。
我运行 2 个报告:
该月的 1st 周二,提取前几个月的所有销售数据。在 EOM 召开前 4 天,我第二次运行该报告,以查找延迟付款,拒收或退款以及经销商付款的情况。
appointments/tasks 将设置为与 excel 中的日期匹配,或者节省一些列空间,我很乐意将其写入 VBA 代码以设置约会:
1st 星期二
EOM 前 4 天
我有一些很棒的入门代码,但是由于我的很多数据需要过滤(仅唯一的日期,并且首选当前日期到将来的日期),因此我不确定我的代码中需要修改哪些内容以使其适合为我的设置。
参考:
http://www.ozgrid.com/forum/showthread.php?t=18157&p=92262#post92262
http://www.vbaexpress.com/forum/showthread.php?25423-Solved-Excel-generate-calendar-appointments-in-Outlook&s=da1942ccfb8b85e3e7eb74ac4c95ed7d&p=177521&viewfull=1#post177521
我当前的代码
Saved/Created in:启用了宏的电子表格,模块(常规,不在工作表名称下),Tools/References/Microsoft Office 14.0 对象库[5]。
Sub StoreReminders()
Dim appOL As Object
Dim objReminder As Object
Set appOL = GetObject(, "Outlook.application")
Set objReminder = appOL.CreateItem(1) ' olAppointmentItem
Set ws1 = Worksheets("sql all 20131228")
objReminder.Start = ws1.Range("a1") & "10:30"
objReminder.Duration = "05:00"
objReminder.Subject = "EOM Reports #1"
objReminder.ReminderMinutesBeforeStart = 30
objReminder.ReminderSet = True
objReminder.Categories = "Acc - 1st Report"
'Becomes: "Acc - EOM Final" when 2nd appointment runs'
objReminder.BusyStatus = olBusy
objReminder.Save
End Sub
我从以下部分开始出现错误:Set appOL = GetObject(, "Outlook.application")
任何帮助都将是非常有用的,我将代码剪切并粘贴在一起,只是无法克服错误。
预先感谢:)
更新
使用新代码时收到以下错误:
编译错误:User-Defined 类型未定义
Sub SetAppt()
Dim olApp As Outlook.Application
Dim olApt As AppointmentItem
Dim MySheet As Worksheet
Set MySheet = Worksheets("sql all 20131228")
Set olApp = New Outlook.Application
Set olApt = olApp.CreateItem(olAppointmentItem)
With olApt
.Start = ws1.Range("n7") + TimeValue("10:30")
'Time is set to 10:30AM on the date of the reminder'
.Duration = "05:00"
.Subject = "EOM Reports #1"
.Location = "Office"
.Body = "Start of Month, EOM Reports"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 60
.Categories = "Acc - 1st Report"
'Becomes: "Acc - EOM Final" when 2nd appointment runs'
.ReminderSet = True
.Save
End With
Set olApt = Nothing
Set olApp = Nothing
End Sub
因此,即使是基本代码也无法正常工作,因此不确定如何包括高级代码(Outlook 用户配置文件,唯一日期)。
1 回答
您需要向 Outlook VBA 模块添加正确的引用。
转到工具->参考,然后选择“ Microsoft Outlook vXX 库”
那应该解决问题。