Results 1 to 3 of 3

Thread: Print an attachment once code has run.

  1. #1
    VBAX Newbie
    Jun 2020

    Question Print an attachment once code has run.

    So I've been playing with VB for a while and now I have an issue in Outlook. I have to send multiple invoices, that are PDF's, to multiple customers. The code below will change the subject line to the file name and make sure that the customer knows where the email is coming from. I want to be able to print the attachments twice. At the moment I quick print them, which isn't too hard but its an extra mouse movement I don't want to do. I have tried creating a separate routine that saves the attachment to the harddrive and prints from there, but I've had limited success. Is there an easy way to achieve what I want? Thanks in advance.

    Sub Inv()
        Dim yMailItem As MailItem
        Dim yAttachment As Attachment
        Dim yFileName As String
        Dim yInspector As Outlook.Inspector
        On Error Resume Next
        Set yMailItem = Outlook.ActiveInspector.CurrentItem
        If yMailItem.Attachments.Count = 0 Then
            Exit Sub
        End If
        yFileName = ""
        For Each yAttachment In yMailItem.Attachments
            If yFileName = "" Then
                yFileName = yAttachment.FileName & " "
                yFileName = yFileName & yAttachment.FileName & " "
                End If
        Next yAttachment
        yMailItem.subject = "Invoice from JOE Bloggs Inc... " & yFileName
              yMailItem.subject = Replace(yMailItem.subject, " image001.png ", " ")
              Set yMailItem = Nothing
        End Sub

  2. #2
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes

  3. #3
    VBAX Newbie
    Jun 2020
    OK thanks I was under the impression I could just print the attachments, but this way it's storing them and printing. Got it working as I want. Thank you for your help.

Tags for this Thread

Posting Permissions

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