none
Print attachments automatically and moves the mail to a new folder RRS feed

  • Question

  • Hello,

    I receive daily a lot of emails with attachments that I want to print out. The attachments are both in .xlsx and .pdf format.

    I tried to make a rules that said print out every email with "invoice" in the subject or body. However, that printed only the body of the email, and not the attachments, which is what I want. 

    I am currently using office proffesional plus 2016. 64-bits version.

    Can anyone help me with this? I'm trying to learn VBA. But I currently don't have a lot of time to practice, so if anyone know where I can find such a script. Or help me out, I would be forever grateful. 

    http://www.slipstick.com/developer/print-attachments-as-they-arrive/

    http://www.vboffice.net/en/developers/print-attachments-automatically

    I found these links. But they are for 32-bit, and older Outlook versions. 

    I don't want to try the script before I am entirely sure its correct for my environmeny. In case it suddenly prints out all the attachments in all folder.

    Question 1: How would a script like this look like

    Question 2: If I activate a script, is it enough if I choose the folder it will operate in, within the rules menu? Or does the folder have to be hard coded? I want this script to only operate within a shared subfolder. 

    -----------------

    The process looks like this:

    1. Find all the attachments in a chosen mailbox, with some chosen keywords in the body/subject field. 

    2. Print all these attachments.

    3. Move the mail to a different mailbox after it has printed the attachment. (Can this be done in the same rule? Just add "move" after "run script")

    Thanks,

     

    Wednesday, March 14, 2018 2:05 PM

All replies

  • Hi Di3sel93,

    The examples in the links can also work for 64 bit version with little modification.

    you must modify the  Declare statement to include the PtrSafe qualifier and you must update any variables within the statement that need to hold 64-bit quantities so that the variables use 64-bit data types.
    VBA 
    Declare statement example modified to include the PtrSafe keyword and updated to use the proper 64-bit ( LongPtr ) data type:

    Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr

    In summary, for code to work in 64-bit versions of Office, you need to locate and modify all existing  Declare statements to use the PtrSafe qualifier. And you need to locate and modify all data types within these Declare statements that reference handles or pointers to use the new 64-bit compatible LongPtr type alias, and types that need to hold 64-bit integrals with the new LongLong data type. Additionally, you must update any user defined types (UDTs) that contain pointers or handles, and 64-bit integrals to use 64-bit data types and verify all variable assignments are correct to prevent type mismatch errors.

    After that you can use the same code on 64 bit version.

    In the first example, If you hard code the folder name then it will move the mail to that folder.

    Reference:

    64-Bit Visual Basic for Applications Overview

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 15, 2018 5:52 AM
    Moderator
  • Okay, thank you so much. 

    So for my code to work I only need to add the line of code that you sent me?

    When I test my script, will it run on all emails or only the ones that I chose to read? By adding a rule saying read only mails that contain e.g. "Invoice", then "run script". 

    Monday, March 19, 2018 6:55 AM
  • Hi Di3sel93,

    You need to modify and declare all functions as ptrsafe functions.

    I again visit the link and find that in that link, there are multiple examples.

    So you need to refer the example as per your requirement.

    Then after code is divided in to many parts in that examples.

    So you need to properly merge code segments so that it can run all together.

    For that ,I suggest you to try to understand the example first.

    You can refer Outlook Object Model to understand that code example.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 19, 2018 8:57 AM
    Moderator