Print Email from sender

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
505
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,
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Watch MrExcel Video

Forum statistics

Threads
1,113,777
Messages
5,544,174
Members
410,596
Latest member
JoeyZ
Top