0

Outlook 2010 VBAで、メール送信時にタスクを作成したいです。

メールのすべての添付ファイルをタスクに追加したいと考えています。

試してみました.Attachments.Add(サポートされていません)。 .Attachments = item.Attachments戻り値のプロパティは読み取り専用です。

可能ですか、またはどうすればメールをタスクに添付できますか?

Public WithEvents myOlApp As Outlook.Application

Private Sub Application_MAPILogonComplete()

End Sub

Private Sub Application_Startup()
    Initialize_handler
End Sub

Public Sub Initialize_handler()
    Set myOlApp = CreateObject("Outlook.Application")
End Sub

Private Sub myOlApp_ItemSend(ByVal item As Object, Cancel As Boolean)
    
Dim intRes As Integer
Dim strMsg As String
Dim objTask As TaskItem
Set objTask = Application.CreateItem(olTaskItem)
Dim strRecip As String
Dim att As MailItem
Dim objMail As Outlook.MailItem

strMsg = "Do you want to create a task for this message?"
intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "Create Task")
      
If intRes = vbNo Then
    Cancel = False
Else
      
    For Each Recipient In item.Recipients
        strRecip = strRecip & vbCrLf & Recipient.Address
    Next Recipient
    
    With objTask
        '.Body = strRecip & vbCrLf & Item.Body
        .Body = item.Body
        .Subject = item.Subject
        .StartDate = item.ReceivedTime
        .ReminderSet = True
        .ReminderTime = DateSerial(Year(Now), Month(Now), Day(Now + 1)) + #8:00:00 AM#
        **.Attachments.Add (item.Attachments)**
        .Save
    End With

    Cancel = False
      
End If

Set objTask = Nothing
    
End Sub
4

2 に答える 2

1

Attachments.Add を使用すると、文字列をパラメーター (完全にクエリ化された添付ファイル名) または Outlook アイテム (MailItem など) として渡すことができます。Attachments コレクションをパラメーターとして渡していますが、それはできません。

添付ファイルごとに、最初に添付ファイルを保存し (Attachment.SaveAsFile)、ファイル名をパラメーターとして渡して一度に 1 つずつタスクに追加します。

于 2013-02-25T17:09:01.057 に答える
1

これが私の最終的なコードです

Public WithEvents myOlApp As Outlook.Application

Private Sub Application_MAPILogonComplete()

End Sub

Private Sub Application_Startup()
 Initialize_handler
End Sub

Public Sub Initialize_handler()
 Set myOlApp = CreateObject("Outlook.Application")
End Sub

Private Sub myOlApp_ItemSend(ByVal item As Object, Cancel As Boolean)

Dim intRes As Integer
Dim strMsg As String
Dim objTask As TaskItem
Set objTask = Application.CreateItem(olTaskItem)
Dim strRecip As String
Dim att As MailItem
Dim objMail As Outlook.MailItem
Dim Msg As Variant

strFolderPath = "C:\temp" ' path to target folder


strMsg = "Do you want to create a task for this message?"
intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "Create Task")


If intRes = vbNo Then
  Cancel = False
Else

For Each Recipient In item.Recipients
    strRecip = strRecip & vbCrLf & Recipient.Address
Next Recipient

item.SaveAs strFolderPath & "\" & "test" & ".msg", olMSG

'item.Save

With objTask
    '.Body = strRecip & vbCrLf & Item.Body
    .Body = item.Body
    .Subject = item.Subject
    .StartDate = item.ReceivedTime
    .ReminderSet = True
    .ReminderTime = DateSerial(Year(Now), Month(Now), Day(Now + 1)) + #8:00:00 AM#
    .Attachments.Add item
    .Save
End With

Cancel = False

End If

Set objTask = Nothing

End Sub
于 2013-02-26T14:57:41.613 に答える