Outlook Office 365 VBA download attachment

Status
Not open for further replies.

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
 
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
 
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.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
X Custom icon (not from Office 365) for a macro in Outlook Outlook VBA and Custom Forms 1
P now on office 365 but getting error messages about missing Outlook 2013 cache folders Using Outlook 2
J Outlook 2016 Trying to get Outlook 2016 to work with Office 365 Using Outlook 0
D Office 365 Outlook desktop app prompts for all account passwords on startup Using Outlook 11
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 Using Outlook 0
Diane Poremsky Outlook.com is moving to Office 365! Using Outlook 3
Diane Poremsky First look: Outlook.com on Office 365 Using Outlook 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? Using Outlook 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 Using Outlook 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
G Save emails as msg file from Outlook Web AddIn (Office JS) Outlook VBA and Custom Forms 0
S Outlook 2016 and Acrobat PDFMaker Office COM Addin Using Outlook 0
J Outlook search bar in Office 2021 Professional Using Outlook 1
S Outlook 2021 How to customize colors Outlook 2021 & Office 2021 on PC Using Outlook 1
J Connect outlook to office365 exchange _without_ signing in office apps Using Outlook 4

Similar threads

Back
Top