Hi Dear,
I had a VBA script to download email attachment applying from rules. It work on Outlook 2010 (Windows 7) but when i try to apply the code on Outlook Office 365 (window 10) it doesn't seen to work at all. Could you kindly enlighten me? below is the code i used.
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Archive\"
Dim SenderEmailAddress As String
SenderEmailAddress = itm.senderName & " "
Dim dateFormat As String
dateFormat = Format(itm.ReceivedTime, "yyyy-mm-dd hh-mm-ss-ms")
Dim dateFormat2 As String
dateFormat2 = Format(Now, "yyyy-mm-dd hh-mm-ss-ms")
Dim LRandomNumber As Integer
LRandomNumber = Int((9999 - 100 + 1) * Rnd + 100)
For Each objAtt In itm.Attachments
If InStr(objAtt.DisplayName, ".xml") Then
objAtt.SaveAsFile saveFolder & "\" & dateFormat & "_Recevie " & LRandomNumber & "_RandomNo " & ReplaceIllegalCharacters(SenderEmailAddress, "_") & dateFormat2 & "_Processed " & objAtt.DisplayName
End If
Next
End Sub
Function ReplaceIllegalCharacters(strIn As String, strChar As String) As String
Dim strSpecialChars As String
Dim i As Long
strSpecialChars = "~""#%&*:<>?{|}/\[]"
For i = 1 To Len(strSpecialChars)
strIn = Replace(strIn, Mid$(strSpecialChars, i, 1), strChar)
Next
ReplaceIllegalCharacters = strIn
End Function
I had a VBA script to download email attachment applying from rules. It work on Outlook 2010 (Windows 7) but when i try to apply the code on Outlook Office 365 (window 10) it doesn't seen to work at all. Could you kindly enlighten me? below is the code i used.
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Archive\"
Dim SenderEmailAddress As String
SenderEmailAddress = itm.senderName & " "
Dim dateFormat As String
dateFormat = Format(itm.ReceivedTime, "yyyy-mm-dd hh-mm-ss-ms")
Dim dateFormat2 As String
dateFormat2 = Format(Now, "yyyy-mm-dd hh-mm-ss-ms")
Dim LRandomNumber As Integer
LRandomNumber = Int((9999 - 100 + 1) * Rnd + 100)
For Each objAtt In itm.Attachments
If InStr(objAtt.DisplayName, ".xml") Then
objAtt.SaveAsFile saveFolder & "\" & dateFormat & "_Recevie " & LRandomNumber & "_RandomNo " & ReplaceIllegalCharacters(SenderEmailAddress, "_") & dateFormat2 & "_Processed " & objAtt.DisplayName
End If
Next
End Sub
Function ReplaceIllegalCharacters(strIn As String, strChar As String) As String
Dim strSpecialChars As String
Dim i As Long
strSpecialChars = "~""#%&*:<>?{|}/\[]"
For i = 1 To Len(strSpecialChars)
strIn = Replace(strIn, Mid$(strSpecialChars, i, 1), strChar)
Next
ReplaceIllegalCharacters = strIn
End Function