Print Email from sender

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
779
Office Version
  1. 365
Hi,

i am using outlook office 365 now and i have a rule and vba script that in 2007 worked fine but now even though i put as default Internet explorer as PDF reader keep asking every time that a new email comes that i have a rule for which program to use open the PDF and I have to print it myself once it opens it before in outlook 2007 will print it automatically, please help.

here is the code:

Code:
Option Explicit



Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
        ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr


'Private Declare 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




Public Sub PrintEmailFromSender(outMailItem As Outlook.MailItem)


    Dim outAttachment As Outlook.Attachment
    Dim saveInFolder As String
    Dim fileType As String, filePath As String
    
    'Folder where attachments in this email will be saved
    
    saveInFolder = "C:\Attachments\"
    
    If Right(saveInFolder, 1) <> "\" Then saveInFolder = saveInFolder & "\"
    
    'Print this email
    
    outMailItem.PrintOut
    
    'Extract and print attachments in this email
    
    For Each outAttachment In outMailItem.Attachments
    
        'Get the file type from the filename
        fileType = Mid(outAttachment.FileName, InStrRev(outAttachment.FileName, ".") + 1)
        
        Select Case LCase(fileType)
        
            'Add additional file types below
            Case "doc", "docx", "pdf" '"xls", "xlsx",
            
                'Save attachment in folder
                filePath = saveInFolder & outAttachment.FileName
                outAttachment.SaveAsFile filePath
            
                'Print saved attachment
                ShellExecute 0, "print", filePath, vbNullString, vbNullString, 0
        End Select
    
    Next


End Sub

Thanks,
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,214,424
Messages
6,119,401
Members
448,893
Latest member
AtariBaby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top