View Full Version : macro runs perfectly on outlook 2013 but not on outlook 2016
Hi all,
I am using a simple macro to auto save attachments from outlook to hard drive, it works perfectly on 2013, but not on 2016. (i have checked trust center and reference, but nothing wrong with it ) there is no error as well. when i click "run the rule" on outlook, nothing happens.
Please help!!!!! Thank you
please see the code below:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim savefolder As String
savefolder = "C:\PERSONAL\Mike\test\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile savefolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
gmayor
08-23-2017, 10:38 PM
It works for me, though I would add
For Each objAtt In itm.Attachments
If Not objAtt.fileName Like "image*.*" Then
objAtt.SaveAsFile savefolder & "\" & objAtt.fileName
End If
Set objAtt = Nothing
Next to eliminate images from the messages, and it will overwrite any existing files of the same name, but the basic code works.
See
http://www.gmayor.com/create_and_employ_a_digital_cert.htm (http://www.gmayor.com/create_and_employ_a_digital_cert.htm)
Hi Gmayor,
Thank you for your reply.
I am using a pc at workplace, so i m not sure if i could do the digital signature.
when i go to vba editor-- tools---digital signature, i click choose, it says "no usable signing certificates are available. please insert your smart card, or contact your administrator to obtain a signing certificate".
then i go to the C drive, i didn't see "root" folder there either.
the attachments wont have same names, it comes with the name and date, all excel file, should i write like " If Not ObjAtt. fileName Like ".xlsm" Then" ?
Thank you !!!!!
By the way, I also run the text under " This outlooksession" , the code shows below, and it works, every time when i restart outlook the msgbox will pop up and shows " Test" . i am not sure if this can give you some information about my situation. Thank you
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
End Sub
Private Sub Application_MAPILogonComplete()
MsgBox "Test"
End Sub
gmayor
08-24-2017, 07:01 AM
If you only want to download Excel files then
change
If Not objAtt.fileName Like "image*.*" Then
to
If objAtt.fileName Like "*.xls*" Then
I don't understand your follow-up message. The code goes in an ordinary module and should be run from a rule, though you can test it by selecting a message with an attachment and running the code
Sub TestMacro()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
saveAttachtoDisk olMsg
lbl_Exit:
Exit Sub
End Sub
Thanks Gmayor, I will try it tomorrow and let you know how it goes, thanks for your reply!!!!!
Hi Gmayor,
Could you tell me what this code test for ?
Can i just run a rule with any email with attachment on this script?
Thanks a lot
Sub TestMacro()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
saveAttachtoDisk olMsg
lbl_Exit:
Exit Sub
End Sub[/QUOTE]
gmayor
08-31-2017, 08:25 PM
The macro simply tests that the main macro works as required before you employ it with your rule. Select a suitable message and run it to establish what happens.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.