2012-10-31 68 views
2

希望得到任何帮助/建议收集Outlook电子邮件响应为任务并填充Excel电子表格

我很新的VBA宏&。我在行政部门工作,我有很多相互关联的任务,我想加快这一过程。

我收到经理的批准电子邮件,告诉我新员工在开始时需要/已批准哪些项目。然后,我需要为每个需要记住为此员工组织的项目创建任务/提醒,并将所有响应转移到共享驱动器上的跟踪电子表格,以便我们可以跟踪新员工的应用程序/项目。

如果我可以设置规则,以便在收到其中一封电子邮件时自动为每个单独的项目创建一个任务,并且“yes”被忽略,并且所有“yes”/no“响应被填充到Excel表格的下一个可用单行中。如果我将Outlook中的任务标记为“已完成”,它将这些信息传递给Excel工作表 - 这可能会更好,这可能是一厢情愿的想法。

例如电子邮件可能是这样的:

Employee Name: John Doe 
Line Manager: Jane Smith 
Start Date: 1/1/2012 
Item 1: Yes 
Item 2: No 
Item 3: Yes 
Item 4: Yes 

和Excel将有一列每个以上。

再次 - 任何帮助/建议大加赞赏

回答

1

This site真正与处理收到的邮件自动帮助,我强烈建议你读得到的Outlook VBA在那里工作的提示。

此代码稍微改编自该页面。以TODO开头的评论行仍然需要填写,但这应该让你开始正确的轨道。

Option Explicit 
' 
' Place this code in the "ThisOutlookSession" class module 
' 
' The code will: 
' 
' Monitor the Inbox 
' Check for the existence of a specific kind of e-mail 
' Move the processed e-mail to a "processed" folder 
' 
Private WithEvents olInboxItems As Items 

' 
' Application_Startup() is a reserved function that will automatically 
' be called when Outlook starts. 
' 
Private Sub Application_Startup() 
    Set olInboxItems = Session.GetDefaultFolder(olFolderInbox).Items 
End Sub 

' 
' This event is fired when the Inbox receives a new message 
' (it can also be fired when manually moving a message from 
' another folder back to the inbox) 
' 
Private Sub olInboxItems_ItemAdd(ByVal Item As Object) 

' On Error Resume Next (commented out for ease of debugging) 

    Dim olMailItem As MailItem 
    Dim strAttachmentName As String 
    Dim Employee() As Variant 
    Dim v() As String 
    Dim i As Long 
    Dim NumItems As Long 
    Dim line As Variant 
    ' 
    ' Only inspect mail items 
    ' Ignore appointments, meetings, tasks, etc. 
    ' 
    If TypeOf Item Is MailItem Then 
     Set olMailItem = Item 
     ' 
     ' Test for specific subject line 
     ' 
     If InStr(olMailItem.Subject, "My Subject Line") > 0 Then 
      ' Get an array of lines in the body of the email 
      v = Split(olMailItem.Body, vbCrLf) 

      ' TODO Parse the array for the data required to populate your Excel file 
      ' TODO Open (or activate) the Excel file 
      ' TODO Add the data to the Excel file 

      ' Once complete, move mail item to OK/Errors folder 
      ' This code assumes the folders already exist 
      ' and are subfolders of the Inbox folder 
      ' 
      ' In older versions of Outlook, olDestFolder 
      ' should be declared as type MAPIFolder 
      ' instead of Folder 
      ' 
      Dim olDestFolder As Folder, strFolderName As String 
      If Err.Number Then 
       strFolderName = "Processed_Errors" 
      Else 
       strFolderName = "Processed_OK" 
      End If 
      ' 
      ' Display Message 
      ' 
      Set olDestFolder = _ 
       Session.GetDefaultFolder(olFolderInbox).Folders(strFolderName) 
      If Err.Number Then 
       olMailItem.Move olDestFolder 
       MsgBox Err.Description + strFolderName + vbCrLf + _ 
         "Check the error folder", _ 
         vbCritical, "Automated e-Mail processing unsuccessful" 
      Else 
       olMailItem.Move olDestFolder 
       MsgBox "Message has been processed and placed in " + strFolderName, _ 
         vbInformation, "Automated e-Mail processing successful" 
      End If 
     End If 
    End If 
    Set Item = Nothing 
    Set olMailItem = Nothing 
End Sub