print attachment straight away; working script edit not working

Gazmoz17

Member
Outlook version
Outlook 2016 64 bit
Email Account
POP3
Hi Diane,

I have used your below script and its a great time saver. Ive adapted it and applied it to one script rule, changing the sDirectory to a diff location.

Tried to duplicate this script calling it a new sub name in new module and changing the sDirectory...then applying to a new script rule and it's not working for some reason, even though exacty the same script other than changes mentioned?
1631883919310.png


Working Script:
Code:
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias _
  "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
  ByVal lpFile As String, ByVal lpParameters As String, _
  ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
 
 Sub PrintAttachments(oMail As Outlook.MailItem)
  Dim colAtts As Outlook.Attachments
  Dim oAtt As Outlook.Attachment
  Dim sFile As String
  Dim sDirectory As String
  Dim sFileType As String
 
  sDirectory = "G:\My Drive\Outlook attachments\End of Day\Sage\"
 
  Set colAtts = oMail.Attachments
 
  If colAtts.Count Then
    For Each oAtt In colAtts
 
' This code looks at the last 4 characters in a filename
      sFileType = LCase$(Right$(oAtt.FileName, 4))
 
      Select Case sFileType
 
' Add additional file types below
      Case ".pdf", ".doc", "docx"
 
        sFile = sDirectory & oAtt.FileName
        oAtt.SaveAsFile sFile
        ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
      End Select
    Next
  End If
End Sub

Not working:

Code:
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias _
  "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
  ByVal lpFile As String, ByVal lpParameters As String, _
  ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
  Sub PrintAttachmentsCash(oMail As Outlook.MailItem)
  Dim colAtts As Outlook.Attachments
  Dim oAtt As Outlook.Attachment
  Dim sFile As String
  Dim sDirectory As String
  Dim sFileType As String
 
  sDirectory = "G:\My Drive\Outlook attachments\Cash Sheet\"
 
  Set colAtts = oMail.Attachments
 
  If colAtts.Count Then
    For Each oAtt In colAtts
 
' This code looks at the last 4 characters in a filename
      sFileType = LCase$(Right$(oAtt.FileName, 4))
 
      Select Case sFileType
 
' Add additional file types below
      Case ".pdf", ".doc", "docx"
 
        sFile = sDirectory & oAtt.FileName
        oAtt.SaveAsFile sFile
        ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
      End Select
    Next
  End If
End Sub

1st script saves and prints summary of card takings for the day.

2nd script I wish to do the same but for cash takings.

1631884308037.png


I think Ive read you literature where is says make the folder move within the vba script rule....but I dont know how to add this. Maybe this is causing the complication. However, the working script rule mirror the above rule steps in outlook (e.g move to folder first/separate from script rule).

Many Thanks
Gareth
 
Similar threads
Thread starter Title Forum Replies Date
R Print email message and attachment in order Outlook VBA and Custom Forms 2
L Outlook 2010 Quick Print Attachment, nothing happend Using Outlook 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 5
S CONTACT FIELD PRINT ORDER Outlook VBA and Custom Forms 1
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
M Batch print without appended trail of repeated e Using Outlook 2
witzker print-list-of-outlook-folders with sort posibility Outlook VBA and Custom Forms 7
M Custom Calendar Print Suggestions? Using Outlook 0
M Print email and, attachments sent in hyperlinks in the email Outlook VBA and Custom Forms 2
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
A Day view - print appointment details Using Outlook 1
I print calendar without subject and details Using Outlook 1
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
oliv- property "is printed" or catching print events Outlook VBA and Custom Forms 2
I Print Automatically Attachments Outlook VBA and Custom Forms 3
Diane Poremsky Print a list of your Outlook folders Using Outlook 0
Diane Poremsky Combine and Print Multiple Outlook Calendars Using Outlook 0
B Print list of previously sent recipients Using Outlook 1
L Outlook 2002: HTML Emails Will Not Print: Please Help Using Outlook 0
A Print first page of a new email Outlook VBA and Custom Forms 7
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
Diane Poremsky No drop down calendars in Outlook 2010 Print Options Using Outlook 0
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
S Macro to print & move selected emails? Using Outlook 3
J Auto print PDF attachments as they arrive with certain words in subject Outlook VBA and Custom Forms 3
H Problems With Outlook 2013 VBA To Send and Print an email Outlook VBA and Custom Forms 1
D Outlook 2013 Categories won't print In color Using Outlook 2
G Calendar monthly view - Print just 3 weeks Using Outlook 5
R Can't modify Outlook view font with IE anymore (even though IE still affects print font) Using Outlook 5
M Print Attachments from another mailbox (not default) Outlook VBA and Custom Forms 2
E Outlook VBA to print attached Pdf to a fax printer and assign fax number Using Outlook 0
C automatically print attachments Using Outlook 4
J Automatically Print PDF When They Are Received Using Outlook 4
M button to send and print emails Using Outlook 26
S How to print ONLY first line of appointments in month view? Using Outlook 1
M print free/busy schedule of an user Using Outlook 2
O For Outlook 2007 - VBA to print attachments Using Outlook 1
W Cannot print Outlook 2007 emails Using Outlook 2
R problem with incomming e-mail I am unable to print full e-mail letter Using Outlook 1
M Custom print contacts Using Outlook 2
E Can't print from Outlook on wifi network Using Outlook 0
E can't print some retail discount coupons Using Outlook 7
J calendar print setup in outlook 2010 Using Outlook 1
J Outlook 2010 using Quick Print to print attachments Using Outlook 1
D Use Outlook 2003 embedded imaged cannot print from the mail preview list Using Outlook 4
J Print next 7 days view of calendar (2010) Using Outlook 3
C Print all emails in a single folder with sent items Using Outlook 2
P Outlook closes down after clicking on the quick print icon. Using Outlook 3
I Outlook 2010 Print Created Date on Drafts Using Outlook 3

Similar threads

Top