PDA

View Full Version : Printing all attachments without a print preview dialog box



tcockerham
12-14-2012, 04:13 PM
Outlook 2010
I am trying to print all attachments in a subfolder withinmy inbox. They will all be .tif and .pdf files. I have a code that will do justthat. It will print the .pdf files without a hitch. But before the code printsthe .tif files, it opens a print preview dialog box for each .tif attachment. Ithought I found a fix when I changed the default program that opens .tif filesto msPaint. If picture files are setup to open in paint, there is no printpreview. However, the files print out in landscape instead of portrait, becausethat is Paint’s default!
I need code to either skip the print preview when printing.tif files, change the .tif file from landscape layout to portrait layout, or away to change the default layout in Paint from landscape to portrait and get itto stay that way.
By the way, I have tried to get the company to send us thefiles in pdf instead of .tif, but so far they have refused.
I have searched long and hard for a solution. A solutionwould save the billing department so much time! Any help will be greatlyappreciated! Thanks!
Here is what I have so far:
Public Declare Function ShellExecute Lib"shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVallpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Function printFile(tifName As String)
ShellExecute 0, "Print", tifName, vbNullString,"", 1
End Function

Public Sub PrintAttachments()
Dim myInbox As MAPIFolder
Dim SubFolder AsMAPIFolder
Dim mailItem As mailItem
Dim attchmt As Attachment
Dim tifName As String
Set myInbox =GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set SubFolder =myInbox.Folders("Print Attachments")
For Each mailItem In SubFolder.Items
For Each attchmt InmailItem.Attachments
If (InStr(1,attchmt, ".tif", vbTextCompare) <> 0) _
Or (InStr(1,attchmt, ".pdf", vbTextCompare) <> 0) Then
tifName ="C:\Temp\" & attchmt.FileName
attchmt.SaveAsFiletifName
Call printFile(tifName)
End If
Next
Next
Set myInbox = Nothing
End Sub