|
Sub FindMail()
Dim xlApp As Object
Dim objFolder As Object
On Error Resume Next
Set xlApp = CreateObject("Excel.Application")
If xlApp Is Nothing Then Exit Sub
Dim FileName As Variant
FileName = xlApp.GetOpenFilename("Excel 文件 (*.xls),*.xls")
If FileName = False Then Exit Sub
Dim wb As Excel.Workbook
Dim ws As Excel.worksheet
Set wb = Workbooks.Open(FileName)
Set ws = wb.Sheets("Sheet1")
Dim rowCount As Long
rowCount = ws.[A65536].End(xlUp).Row
If rowCount = 0 Then
MsgBox "Excel文件没有数据"
Exit Sub
End If
Dim objSourceFolder As Outlook.MAPIFolder
Set objSourceFolder = GetNamespace("MAPI").PickFolder
Dim appItem As Outlook.mailItem
Dim objOutlook As New Outlook.Application
Set mobjOutlook = objOutlook.GetNamespace("MAPI")
Set objFolder = mobjOutlook.GetDefaultFolder(olFolderInbox)
For Each objItem In objFolder.Items
If objItem.Class = olMail Then
Set appItem = objItem
For i = 1 To rowCount
If (InStr(1, appItem.Subject, ws.Cells(i, 1)) <> 0) Then
appItem.Move objSourceFolder
Exit For
End If
Next
End If
Next
xlApp.Quit
Set xlApp = Nothing
MsgBox "完成"
End Sub |
|