Consulting

Results 1 to 8 of 8

Thread: macro runs perfectly on outlook 2013 but not on outlook 2016

  1. #1
    VBAX Regular
    Joined
    Jul 2017
    Posts
    24
    Location

    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
    Last edited by SamT; 08-23-2017 at 01:37 PM.

  2. #2
    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_emp...gital_cert.htm
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Jul 2017
    Posts
    24
    Location
    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 !!!!!

  4. #4
    VBAX Regular
    Joined
    Jul 2017
    Posts
    24
    Location
    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

  5. #5
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  6. #6
    VBAX Regular
    Joined
    Jul 2017
    Posts
    24
    Location
    Thanks Gmayor, I will try it tomorrow and let you know how it goes, thanks for your reply!!!!!

  7. #7
    VBAX Regular
    Joined
    Jul 2017
    Posts
    24
    Location
    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]

  8. #8
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •