Outlook Office 365 VBA download attachment

kyoichi83

New Member
Outlook version
Outlook 2019 32-bit
Email Account
Exchange Server
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
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It should work on it too,. Do you have macro security set to low or sign the macro with a selfsig?

This folder exists? saveFolder = "C:\Archive\"

Test it by stepping though it -select a message then use this macro - use the Step into button and watch what it does.

Sub TestsaveAttachtoDisk()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
saveAttachtoDisk objItem

End Sub
 

kyoichi83

New Member
Outlook version
Outlook 2019 32-bit
Email Account
Exchange Server
It should work on it too,. Do you have macro security set to low or sign the macro with a selfsig?

This folder exists? saveFolder = "C:\Archive\"

Test it by stepping though it -select a message then use this macro - use the Step into button and watch what it does.

Sub TestsaveAttachtoDisk()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
saveAttachtoDisk objItem

End Sub
Thank you! Marco had been set to low and folder exist too. I will try with your recommendation.
 
Similar threads
Thread starter Title Forum Replies Date
L Ideas for Setup with New Office 365 Family Subscription (Outlook) Using Outlook.com accounts in Outlook 3
D Sending email from Office 365 alias in Outlook Using Outlook 3
D Outlook 2016 Deleting emails without affecting folder structure - Outlook Office 365 Using Outlook 3
T I'm thinking about moving from outlook.com to the Outlook I have in my Office 365 Using Outlook 1
M Outlook .com group does not show up in Outlook for office 365 home Using Outlook 3
Jennifer Murphy Outlook can't connect to Office 365 at resort hotel Using Outlook.com accounts in Outlook 1
J Outlook Office 365 Win 10 how do I control background colors of events? Using Outlook 1
B Migrate Outlook 2007 to Office 365 Using Outlook 3
L Outlook Office 365 client: won't remember my setting File, not to collapse ribbon Using Outlook 2
glnz How set up new IMAP on Outlook-Office 365 and merge in pst from Outlook 2003 for same two email accounts? Using Outlook 5
G Calendar View in Outlook Office 365 - Doesn't show enough hours, and the 30/60 min choice isn't the solution Using Outlook 4
O Office 365 Outlook - mark to download Using Outlook 0
V Multiple Calendars in Outlook To-Do Bar; Office 365 Using Outlook 3
O Office 365 - Outlook - Password protect your mailbox Using Outlook 7
Horsepower Office Outlook 365 home opens slower than a month ago Using Outlook 8
L Need to import multiple Outlook files to Office 365 Account Using Outlook 4
H Custom autoforwarding, sending mail through outlook office 365 Using Outlook 1
L Outlook Office 365 cached mode crashing Using Outlook 0
mrje1 Outlook 2016 Manual Email Account Setup, what is the Office 365 option etc., and Crashes Using Outlook 0
J Office 365 and Outlook connection issues Using Outlook.com accounts in Outlook 3
Diane Poremsky New in Office 365 and Outlook.com: Interesting Calendars New Slipstick.com Articles 0
Diane Poremsky Outlook.com is moving to Office 365! New Slipstick.com Articles 3
Diane Poremsky First look: Outlook.com on Office 365 New Slipstick.com Articles 0
J Unable to link email messages in BCM using a single microsoft office 365 account in outlook 2013 BCM (Business Contact Manager) 1
H Outlook 2010 & office 365 ...what a mess Using Outlook 1
L Synching Office 365 contacts to Iphone MS Outlook client Using Outlook 5
T Outlook 2013 Outlook.com to Office 365 Exchange: When? Using Outlook.com accounts in Outlook 3
C GoDaddy office 365 setup wizard erased old Outlook emails? Using Outlook 14
B Syncing Office 365 folders to match Outlook 2013 Using Outlook 3
Diane Poremsky Outlook 2007 with Office 365? New Slipstick.com Articles 0
L Office 365 Outlook changing default contact folder Using Outlook 0
R Outlook Office 365 not saving addresses Using Outlook 0
I Create custom Outlook 2013 Rule in Office 365 Outlook VBA and Custom Forms 5
Diane Poremsky First look: Outlook.com on Office 365 New Slipstick.com Articles 0
L what is safe size for pst of Outlook 2013 via Office 365 exchange? Using Outlook 1
wisedave Office 365 Outlook - Emails send but don't receive Using Outlook 12
A Exporting email in outlook 2013 with Office 365 Using Outlook 1
J Office 365 small business/Outlook 2013 issues Using Outlook.com accounts in Outlook 1
N How to install BCM for Outlook 2013 in Office 365 Small Business Premium BCM (Business Contact Manager) 1
S Outlook 2013. Adding office 365 email account causes 'The operation failed' Using Outlook 2
P Using Outlook to view Office 365 e-Mail Using Outlook 1
A Outlook (and Office) 2019 Logging Using Outlook 2
glnz Can Word Normal.dotm interfere with Outlook? Office 2016 Using Outlook 5
M Office 2016 Outlook is forgetting passwords Using Outlook 15
E Can one still buy Outlook (or Office) 2016? Using Outlook 6
P outlook addin unloaded in office 2007 Using Outlook 0
K Help.... Office Outlook 2016 Using Outlook 1
P MS OFFICE 2013 - Outlook locking up when using the sent on behalf of feature in VB Using Outlook 3
Diane Poremsky How to Uninstall Outlook from an Office Installation New Slipstick.com Articles 0
Diane Poremsky Cannot start Microsoft Office Outlook Error Message New Slipstick.com Articles 0

Similar threads

Top