- 我希望每个约会的标题/主题前面都加上其时间。
- 我希望标题能够自动更新以对应事件的时间(如果我更改日期,标题的日期也会更改)。
例子:
10:00-12:00 Meeting with Joe
- 尝试寻找内置方法失败了。选项、设置、规则中什么也没有,我几乎搜遍了整个界面。
- 宏可能是个不错的选择。我没有 VB,不过如果有人能贴出一些指导链接,我也不怕学习。
- 我在谷歌搜索中没有找到日历的任何“事后”约会保存事件。是否有一个我可以事后激活宏的事件?
这可能吗?
答案1
下面的代码片段可以很好地完成工作,大约需要 3-4 个小时才能写完,而且写起来相当麻烦 ;)
非常欢迎任何关于如何使代码更简洁、结构更好的评论。
我对那些我认为对后续读者来说有点不清楚的部分留下了评论。如果你读了这篇文章却什么都不懂,那就留下评论吧!:)
Dim WithEvents curCal As Items ' set var as the holder of Item events
Public lastSavedAppointmentStart As Date ' variable so we won't infinitely loop when saving Items
Public lastSavedAppointmentEnd As Date
Public justSaved As Boolean
' Some initial Startup Code from slipstick.com
' F5 while the cursor is in this sub (in the vba editor)
' will reload the so called "project"
Private Sub Application_Startup()
Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")
Set curCal = NS.GetDefaultFolder(olFolderCalendar).Items
Set NS = Nothing
lastSavedAppointmentStart = Now()
lastSavedAppointmentEnd = Now()
End Sub
Private Sub checkPrependtime(ByVal Item As Object)
Dim isntLastAppt As Boolean
isntLastAppt = isntLastSavedAppointment(Item)
If justSaved = False And isntLastAppt Then
If Not isTimePrepended(Item) Then
Call saveLastAppointment(Item)
Call prependTime(Item)
Else
Call removePrependedTime(Item)
End If
Else
justSaved = False
End If
End Sub
Function isntLastSavedAppointment(ByVal Item As Outlook.AppointmentItem) As Boolean
isntLastSavedAppointment = lastSavedAppointmentStart <> Item.start Or lastSavedAppointmentEnd <> Item.End
End Function
Private Sub saveLastAppointment(ByVal Item As Outlook.AppointmentItem)
justSaved = True
lastSavedAppointmentStart = Item.start
lastSavedAppointmentEnd = Item.End
End Sub
Private Sub removePrependedTime(ByVal Item As Outlook.AppointmentItem)
Set lastSavedAppointment = Nothing
Dim oldSubject As String
' Cut out the time part of the subject (e.g. 13:00-15:00 Meeting with Joe)
' returns Meeting with Joe
oldSubject = Mid(Item.Subject, 13, Len(Item.Subject))
Item.Subject = oldSubject
Item.Save
End Sub
Private Sub prependTime(ByVal appt As Outlook.AppointmentItem)
Dim newSubject As String, apptStart As Date, apptEnd As Date
Set lastSavedAppointment = appt
newSubject = Format(appt.start, "hh:mm") & "-" & Format(appt.End, "hh:mm") & " " & appt.Subject
appt.Subject = newSubject
appt.Save
End Sub
' Check whether the third char is :
' If time is prepended (e.g. Item.subject is something like
' "12:00-13:00 Meeting with joe" Then third char is always :)
Function isTimePrepended(ByVal Item As Outlook.AppointmentItem) As Boolean
isTimePrepended = InStr(3, Item.Subject, ":")
End Function
' BEGIN event handlers
Private Sub curCal_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.AppointmentItem Then
Call prependTime(Item)
End If
End Sub
Private Sub curCal_ItemChange(ByVal Item As Object)
If TypeOf Item Is Outlook.AppointmentItem Then
Call checkPrependtime(Item)
End If
End Sub
' END event handlers
答案2
这是可能的,至少在 OWA 和 Outlook 2013 中,也可能在 Outlook 2010 中。我们最近才开始在办公室开发 Outlook 应用程序,因此不幸的是我无法提供任何代码来帮助您入门。
请阅读以下文章: http://msdn.microsoft.com/en-us/library/dn574747%28v=office.15%29