Auto Print to Outlook 10 using a VB script signaling out individual email attachments RRS feed

  • Question

  • Hello,

    I have the following script that I will put at the bottom that will auto print attachments but I only want certain emails with attachments to print...there are maybe 5 or so...can I hard code them in this script or do I need to make a rule for each one...I currently call this script from the "rule" but it grabs every email that has an attachment.

    so if I only want to auto print from an email that is from and and would you recommend doing that?

    Thank you for all ideas! is the script I am currently using:

    Sub LSPrint(Item As Outlook.MailItem)

    On Error GoTo OError

    'detect Temp

    Dim oFS As FileSystemObject

    Dim sTempFolder As String

    Set oFS = New FileSystemObject

    'Temporary Folder Path

    sTempFolder = oFS.GetSpecialFolder(TemporaryFolder)

    'creates a special temp folder

    cTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")

    MkDir (cTmpFld)

    'save & print

    Dim oAtt As Attachment

    For Each oAtt In Item.Attachments

    FileName = oAtt.FileName

    FullFile = cTmpFld & "\" & FileName

    'save attachment

    oAtt.SaveAsFile (FullFile)

    'prints attachment

    Set objShell = CreateObject("Shell.Application")

    Set objFolder = objShell.NameSpace(0)

    Set objFolderItem = objFolder.ParseName(FullFile)

    objFolderItem.InvokeVerbEx ("print")

    Next oAtt


    If Not oFS Is Nothing Then Set oFS = Nothing

    If Not objFolder Is Nothing Then Set objFolder = Nothing

    If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing

    If Not objShell Is Nothing Then Set objShell = Nothing


    If Err <> 0 Then

    MsgBox Err.Number & " - " & Err.Description


    End If

    Exit Sub

    End Sub

    Thursday, February 18, 2016 11:33 PM


  • Hi Latte14,

    >> so if I only want to auto print from an email that is from and and

    If you only want to print the special mailItems, I suggest you check the SenderEmailAddress property of MailItem.

    Here is a simple code:

    Sub SetFlagIcon()  
     Dim mpfInbox As Outlook.Folder  
     Dim obj As Outlook.MailItem  
     Dim i As Integer  
     Set mpfInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Test")  
     ' Loop all items in the Inbox\Test Folder  
     For i = 1 To mpfInbox.Items.Count  
     If mpfInbox.Items(i).Class = olMail Then  
     Set obj = mpfInbox.Items.Item(i)  
     If obj.SenderEmailAddress = "" Then  
     'Set the yellow flag icon  
     obj.FlagIcon = olYellowFlagIcon  
     End If  
     End If  
    End Sub

    For more information, you could refer the link below:

    # MailItem.SenderEmailAddress Property (Outlook)

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 22, 2016 2:20 AM