Printing Tiff/JPG attachment

H

Henk Pols

Does anyone have the vba code to print an Tiff/JPG attachment?

I am writng a code that will print a selected E-mail and all attached
documents. So far Iam able to print .doc and .xls attachments, I am missing
the correct code to print .tif and .jpg attachment.

Below is my code sofar:
Sub MyPrint()
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim Atmt As Attachment
Dim FileName As String
Dim PrtProg As String
Dim cmd As String
Dim x As Integer

Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
myOlSel.Item(x).PrintOut
For Each Atmt In myOlSel.Item(x).Attachments
FileName = "C:\Windows\Temp\" & Atmt.FileName
Atmt.SaveAsFile FileName
Select Case Right(FileName, 3)
Case "xls":
Dim xlApp As Excel.Application
Dim wb As Excel.Workbook
Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open(FileName)
wb.PrintOut
xlApp.Quit
Set wb = Nothing
Set xlApp = Nothing
Case "doc":
Dim wdApp As Word.Application
Dim doc As Word.Document
Set wdApp = New Word.Application
Set doc = wdApp.Documents.Open(FileName)
doc.PrintOut
wdApp.Quit False
Set doc = Nothing
Set wdApp = Nothing
Case "tiff":
Case "jpg":
Case "bmp":
Case "pdf": 'Via Arobat32.exe
Case "dwg": 'Via ACad32
Case Else:
End Select
Next Atmt
Next x
End Sub

Thanks in advance for any input on this issue.
 
J

JP

If you have a program that can print images using command line
switches, just call it using the Shell function.

Shell "C:\image_printer\image_printer.exe", vbHide

For example, Irfanview has a /print option which can print an image to
the default printer and then close the program. So it would be
something like

Shell "C:\your path to Irfanview\irfanview.exe /print" &
yourfilename.jpg

HTH,
JP
 
H

Henk Pols

JP Thanks for your input, however I have already solved the issue.
For you info I use the following code:
Case "bmp", "jpg", "tif":
Dim PCmd, objShell, oExec
Dim Printer As String

Printer = GetDefaultPrinter ' Own declared Function
PCmd = "rundll32 shimgvw.dll,ImageView_PrintTo /pt """ &
FileName & """ """ & Printer
Set objShell = CreateObject("Wscript.Shell")
Set oExec = objShell.Exec(PCmd)

Do While oExec.Status = 0
WScript.Sleep 100
Loop
' Clean up
Set oExec = Nothing
Set objShell = Nothing
Henk.

"JP" <[email protected]> schreef in bericht
If you have a program that can print images using command line
switches, just call it using the Shell function.

Shell "C:\image_printer\image_printer.exe", vbHide

For example, Irfanview has a /print option which can print an image to
the default printer and then close the program. So it would be
something like

Shell "C:\your path to Irfanview\irfanview.exe /print" &
yourfilename.jpg

HTH,
JP
 
J

JP

Thanks for sharing, I'm sure there are others with the same issue who
could use your code.

--JP
 
S

syed rizwan shah iqbal

Hi i know the top post is so old but i use that example and doing batch print from outlook using VBA code.

My Code is:

Dim blnPrinted As Boolean
blnPrinted = False

Dim strCommand As String
strCommand = "C:\Program Files\IrfanView \i_view32.exe " & vstrPathAtt & "/print"
Shell strCommand, vbHide
'Sleep 10000
blnPrinted = True

Finally:

PrintAtt_JPEG = blnPrinted
Exit Function
________________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top