PDA

View Full Version : Print an attachment once code has run.



rich_w
06-12-2020, 02:33 AM
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 & " "
Else
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

gmayor
06-13-2020, 08:42 PM
See http://www.vbaexpress.com/forum/showthread.php?67509-Compiling-Error-Auto-Print-Attachments

rich_w
06-16-2020, 05:35 AM
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.:clap::clap::clap::clap::clap::clap::clap::clap::clap::clap::clap::cla p: