如何编写在电子邮件主题行中搜索特定单词的IF语句 [英] How do I write an IF statement that searches for a specific word in an email's subject line
本文介绍了如何编写在电子邮件主题行中搜索特定单词的IF语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个规则+脚本设置在Outlook中。该规则在电子邮件主题中查找特定的单词,然后运行下面的脚本(在模块中定义)。但它似乎只适用于我的个人收件箱,而不是群组收件箱。下面是代码的工作原理。
I've got a rule + script setup in outlook. The rule looks for specific words in the email subject and then runs the script (defined in Modules) below. But it seems to be only working for my personal inbox and not a group inbox. The below is the code that works.
评论中的行是我试图解决的问题。
The lines in comments are me trying to work it out.
Public Sub saveAttachtoDisk(item As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "d:\temp\"
Dim objNS As Outlook.NameSpace
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
'Set objNS = olApp.GetNamespace("MAPI")
'Set myRecipient = objNS.CreateRecipient("XXXXXXX")
'myRecipient.Resolve
'set Items = objNS.GetSharedDefaultFolder(myRecipient, olFolderInbox).Items
'Dim itm As Outlook.MailItem
' If TypeName(item) = "MailItem" Then
' Set itm = item
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
推荐答案
这是如何去阅读电子邮件主题,以启动更多的代码:
This is how to go and read the email subject to launch further code :
Public Sub saveAttachtoDisk()
Dim olApp As Outlook.Application, _
oNS As Outlook.NameSpace, _
oFld As Outlook.Folder, _
oMails As Outlook.Items, _
oMail As Outlook.MailItem, _
oAtt As Outlook.Attachment, _
SaveFolder As String
SaveFolder = "d:\temp\"
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number > 0 Then Set olApp = CreateObject("Outlook.Application")
On Error GoTo 0
Set oNS = olApp.GetNamespace("MAPI")
Set oFld = oNS.GetDefaultFolder(olFolderInbox)
Set oMails = oFld.Items
For Each oMail In oMails
If InStr(1, oMail.Subject, "Txt_to_Find") Then
'----Your code comes here
For Each oAtt In oMail.Attachments
oAtt.SaveAsFile SaveFolder & "\" & oAtt.DisplayName
Set oAtt = Nothing
Next oAtt
Else
End If
Next oMail
End Sub
这篇关于如何编写在电子邮件主题行中搜索特定单词的IF语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文