因此,我正在開發一些需要約會的代碼,並從約會創建一些任務,並在發送前檢查是否有附件。如何在添加參加者後將附件添加到AppointmentItem?
當我沒有其他與會者時,代碼工作正常。但是,一旦添加了與會者,代碼就會卡在打開文件附件對話框中。的Bleh!
我已經把它貼下面的代碼:
Public WithEvents myItem As Outlook.appointmentitem
Private Sub myItem_Write(Cancel As Boolean)
Dim myResult As Integer
Dim olApp As Outlook.Application
Dim olTsk As TaskItem
Dim olAppt As appointmentitem
Dim TskSubj As String
Dim ApptSubj As String
Dim olNS As Outlook.NameSpace
Dim myolApp As Outlook.Application
Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)
With olTsk
olTsk.DueDate = myItem.Start - 1
olTsk.Subject = myItem.Subject
olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "Send BCP Docs")
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing
Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)
With olTsk
olTsk.DueDate = myItem.Start + 30
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")
olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "BCP Updates due")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing
Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)
With olTsk
olTsk.DueDate = myItem.Start + 20
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")
olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "BIA Team Leader Signature")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing
Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)
With olTsk
olTsk.DueDate = myItem.Start + 30
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")
olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "BIA Executive Approver Signature")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing
Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)
With olTsk
olTsk.DueDate = myItem.Start + 1
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")
olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "Send BIA Link")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing
Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)
With olTsk
olTsk.DueDate = myItem.Start + 30
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")
olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "LDRPS")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing
MSG1 = MsgBox("Are BCP and BIA attached?", vbYesNo, "Yadda?")
If MSG1 = vbYes Then
myItem.Send
Else
MsgBox "Dude! What are you thinking??"
Dim myInspector As Outlook.Inspector
Set myolApp = CreateObject("Outlook.Application")
Set myInspector = myItem.GetInspector
Application.ActiveInspector.CommandBars.findcontrol(ID:=1079).Execute
Exit Sub
End If
End Sub
的代碼棒上:
Application.ActiveInspector.CommandBars.findcontrol(ID:=1079).Execute
任何幫助將大大appriciated
歡迎來到Stack Overflow。如果您只需要幫助調試一行,請不要發佈您的完整代碼。這不關我的事,但你的代碼看起來需要重構。對於初學者來說,如果這是Outlook VBA,那麼你爲什麼使用'New'關鍵字?甚至不少於六次。 – JimmyPena