下载作为Outlook项目的Outlook附件
问题描述:
如何自动下载作为Outlook项目的附件?下载作为Outlook项目的Outlook附件
我尝试使用这个脚本VBA下载,但它并不适用于Outlook项目工作。它适用于.txt或任何其他类型的附件。
Public Sub Savisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "D:\userdata\sanakkay\Desktop\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
答
Outlook项目可能被命名为/具有文件名中非法字符的主题。
例如在
任务名称冒号:KM_CEM_GY
有解决此至少两个标准方法。
Outlook 2010 VBA How to save message including attachment
Private Sub ReplaceCharsForFileName(sName As String, sChr As String)
sName = Replace(sName, "'", sChr)
sName = Replace(sName, "*", sChr)
sName = Replace(sName, "/", sChr)
sName = Replace(sName, "\", sChr)
sName = Replace(sName, ":", sChr)
sName = Replace(sName, "?", sChr)
sName = Replace(sName, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub
VBA dialog boxes automatically answer solution
Function StripIllegalChar(StrInput)
Dim RegX As Object
Set RegX = CreateObject("vbscript.regexp")
RegX.Pattern = "[\" & Chr(34) & "\!\@\#\$\%\^\&\*\(\)\=\+\|\[\]\{\}\`\'\;\:\<\>\?\/\,]"
RegX.IgnoreCase = True
RegX.Global = True
StripIllegalChar = RegX.Replace(StrInput, "")
ExitFunction:
Set RegX = Nothing
End Function
答
如果你想下载从Outlook附件,试试这个。 私人小组GetAttachments()
Dim ns As Namespace
Dim Inbox As Outlook.MAPIFolder
Dim Item As Object
Dim Atmt As Outlook.Attachment
Dim FileName As String
Set ns = GetNamespace("MAPI")
Set Inbox = ns.Folders("MailboxName").Folders("Inbox")
If Inbox.Items.Count = 0 Then
MsgBox "There are no messages in the Inbox.", vbInformation, _
"Nothing Found"
Exit Sub
End If
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
If Atmt.Type = 1 And InStr(Atmt, "xlsx") > 0 Then
FileName = "C:\attachments\" & Atmt.FileName
Atmt.SaveAsFile FileName
End If
Next Atmt
Next Item
末次 设置到MS Outlook的引用,请记住, “MailboxName” 是您的电子邮件地址。
这看起来不像'vb.net' ...以及它的一些与'vb6'混合。你能描述一下“它不适用于展望项目”吗? – Codexer
sry ..........其不是vb.net的vba代码。此代码适用于.txt或.excel或其他格式的附件,但不适用于文件类型展望。查看图像以了解Outlook格式的外观 –