none
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 fax@somename.com and support@somename.com and helpdesk@somename.com....how would you recommend doing that?

    Thank you for all ideas!...here 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

    'Cleanup

    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

    OError:

    If Err <> 0 Then

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

    Err.Clear

    End If

    Exit Sub

    End Sub

    Thursday, February 18, 2016 11:33 PM

Answers

  • Hi Latte14,

    >> so if I only want to auto print from an email that is from fax@somename.com and support@somename.com and helpdesk@somename.com

    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 = "someone@example.com" Then  
     'Set the yellow flag icon  
     obj.FlagIcon = olYellowFlagIcon  
     obj.Save  
     End If  
     End If  
     Next  
    End Sub

    For more information, you could refer the link below:

    # MailItem.SenderEmailAddress Property (Outlook)
    https://msdn.microsoft.com/EN-US/library/office/ff868262.aspx

    Best Regards,

    Edward


    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