我有一个用户表单,当我发送电子邮件时提示(效果很好。不是问题),当我点击表单上的按钮时,它会将电子邮件移动到相应的文件夹。
我现在想要的是,当我的收件箱中的邮件从未读到读取时,会提示相同的用户表单(而不是重复)。然后,用户窗体上的按钮会将该消息移动到相应的文件夹。
发送电子邮件时调出userform的代码:
Private Sub Application_ItemSend(ByVal Item As Object, cancel As Boolean)
UserForm1.Show vbModal
cancel = False
End Sub
userform按钮的代码段:
Private Sub CommandButton1_Click()
On Error GoTo error_movemessage
Dim myolapp As New Outlook.Application
Dim mynamespace As Outlook.NameSpace
Dim myinbox As Outlook.MAPIFolder
Dim mydestfolder As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim myItem As Object
Set mynamespace = myolapp.GetNamespace("MAPI")
Set myinbox = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("RetainPermanently")
Set myitems = myinbox.Items
Set mydestfolder = myinbox
Set myItem = Application.ActiveInspector.CurrentItem
myItem.Move mydestfolder
Unload Me
exit_CommandButton1_Click:
Exit Sub
error_movemessage:
MsgBox "ERROR! " & Err.Description
Resume exit_CommandButton1_Click
End Sub
我搜索了这个难题的各个方面,最终结果不成功。提前谢谢!
更新
Private Sub getselecteditem_click()
Dim oApp As New Outlook.Application
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection
Dim oItem As Object
Set oExp = oApp.Application
Set oSel = oExp.Selection
For i = 1 To oSel.Count
Set oItem = oSel.Item(i)
If oItem.Class = olMail Then
End If
Next i
End Sub
Sub oItem_PropertyChange(ByVal Name As String)
Select Case Name
Case "UnRead"
If oItem.UnRead = False Then
UserForm2.Show vbModal
End If
End Select
End Sub
然而,仍然无法发挥作用。
我意识到我已经做得比实际需要的要困难得多。每当我加载一个恰好未读的mailitem时,我可以简单地将其拉出来。这是一个更新:
Private Sub Application_ItemLoad(ByVal Item As Object)
If Item.Class = olMail Then
If Item.UnRead Then
UserForm2.Show vbModal
End If
End If
End Sub
答案 0 :(得分:0)
首先,如果您在发送邮件时将项目移动到其他文件夹,则表示您遇到问题 - 如果您希望将邮件保存在“已发送邮件”以外的文件夹中,请设置MailItem.SaveSentMessageFolder属性。 / p>
要在读取状态更改时移动消息,请跟踪Explorer.SelectionChange事件。当SelectionChange事件触发时,开始跟踪来自Explorer.Selection集合的多条消息上的事件(可能有多个消息,但您可以将第一个消息作为概念证明)。当MailItem.PropertyChange事件在Unread属性上触发时,显示提示并移动消息。