【发布时间】:2020-03-17 15:52:54
【问题描述】:
我在 Outlook VBA ThisOutlookSession 中有这段代码,它没有给出任何错误,但没有下载附件。任何想法
Public WithEvents objInboxItems As Outlook.Items
Private Sub Application_Startup()
Set objInboxItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim objMail As Outlook.MailItem
Dim strSenderAddress As String
Dim strSenderDomain As String
Dim objAttachment As Attachment
Dim strFolderPath As String
Dim strFileName As String
If Item.Class = olMail Then
Set objMail = Item
'Get sender domain
strSenderAddress = objMail.SenderEmailAddress
strSenderDomain = Right(strSenderAddress, Len(strSenderAddress) - InStr(strSenderAddress, "@"))
'Change to the specific domain as per your needs
If strSenderDomain = "gmail.com" Then
If strSenderAddress = "vs@gmail.com" Then
If objMail.Attachments.Count > 0 Then
For Each objAttachment In objMail.Attachments
strFolderPath = "E:\Cisco - Qutar\Performance Report Automation\"
strFileName = objMail.Subject & " " & Chr(45) & " " & objAttachment.FileName
objAttachment.SaveAsFile strFolderPath & strFileName
Next
End If
End If
End If
End If
End Sub
已更新
【问题讨论】:
-
嗨。如果 strSenderDomain = "vs@gmail.com" 然后你希望得到 vs@gmail.com,但是 var strSenderDomain 与域 gmail.com 相同...将 "vs@gmail.com" 更改为 " gmail.com”并且应该可以工作
-
嗨 Luis,我只需要一个特定的发件人,如果这样做的话,可能会有来自不同用户的电子邮件,它会下载来自 gmail 发件人的所有邮件。 ''' 如果 strSenderDomain = "gmail.com"',仍然没有下载
-
在这种情况下更改 --> If strSenderDomain = "vs@gmail.com" Then If strSenderAddress = "vs@gmail.com" Then
-
改了,还是不行,''' If strSenderAddress = "vs@gmail.com" Then '''
-
if 是否输入?并在每个?