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:
Thanks,
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,