-1

我将 Outlook 消息拖到名为“电子邮件临时文件夹”的特定文件夹中,并希望自动回复该消息。

我保存在“电子邮件临时文件夹”中的消息的标题名称可以是任何东西。我无法获得文件的标题名称。所以我尝试遍历“电子邮件临时文件夹”中的文件,然后Set FileItemToUse = objFile

但是,有一个错误:object does not support this property or method on this line。.ReplyAll

我怎样才能FileItemToUse变成一个展望项目?

Sub outlookActivate1()

  Dim OutApp As Outlook.Application
  Dim OutMail As Outlook.MailItem
  Dim fso As New FileSystemObject
  Dim objFolder As Object
  Dim objFile As Object
  Dim FileItemToUse As Object
  Dim i As Long

  Set OutApp = CreateObject("Outlook.Application")

  strPath = "C:\Users\admin\Desktop\email temp folder" & "\"
  strFiles = Dir(strPath & "*.*")
  Set objFolder = fso.GetFolder(strPath)

  For Each objFile In objFolder.Files 

    If i = 0 Then    
      Set FileItemToUse = objFile           
    End If

  Next objFile


  With FileItemToUse

    .ReplyAll
    .BCC = ""
    .Subject = "Hi"
    .HTMLBody = "testing"
    .BodyFormat = olFormatHTML
    .display

  End With

  Set OutMail = Nothing
  Set OutApp = Nothing

End Sub
4

2 回答 2

0

所以我尝试遍历“电子邮件临时文件夹”中的文件并设置 FileItemToUse = objFile

以这种方式完成工作是不可能的。

当您将消息文件 (.msg) 文件拖到特定文件夹时,会触发ItemAdd事件。因此,您需要处理该事件以获取对应于已删除文件的 MailItem 对象。然后您可以使用回复回复所有方法。

于 2015-02-22T09:57:30.697 回答
0

您的代码应类似于以下内容:

Sub ReplyToFilesInFolder(SourceFolderName As String)
    Dim FSO As Scripting.FileSystemObject
    Dim SourceFolder As Scripting.Folder
    Dim FileItem As Scripting.File
    Dim strFile
    Dim strFileType
    Dim openMsg As MailItem     
    Dim strFolderpath As String

    Set FSO = New Scripting.FileSystemObject
    Set SourceFolder = FSO.GetFolder(SourceFolderName)

    For Each FileItem In SourceFolder.Files    
       strFile = FileItem.name

       ' This code looks at the last 4 characters in a filename
       ' If we wanted more than .msg, we'd use Case Select statement
       strFileType = LCase$(Right$(strFile, 4))
       If strFileType = ".msg" Then
           Debug.Print FileItem.Path

           Set openMsg = Application.CreateItemFromTemplate(FileItem.Path)

           ' do whatever is needed to reply

           openMsg.Close olDiscard   
           Set openMsg = Nothing

           ' end do whatever
      End If
    Next FileItem

    Set FileItem = Nothing
    Set SourceFolder = Nothing
    Set FSO = Nothing      
End Sub

这个(未经测试的)剪辑受到这篇文章的启发。Microsoft Scripting Runtime必须作为项目参考。

于 2015-02-22T09:24:19.807 回答