Sub printExcelAttachments()
Dim itms As Object
Dim itm As Object
Dim sh As Object
Dim att As Object
Dim objFSO As Object
Dim objTempFolder As Object
Dim dlg As FileDialog
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
Set itms = Application.ActiveExplorer.Selection
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTempFolder = objFSO.GetSpecialFolder(2)
Set xlApp = CreateObject("excel.application")
For Each itm In itms
For Each att In itm.Attachments
Select Case LCase(Right(att.Filename, Len(att.Filename) - InStrRev(att.Filename, ".")))
Case "xls"
att.SaveAsFile objTempFolder & "\" & att.Filename
xlApp.workbooks.Open objTempFolder & "\" & att.Filename
For Each xlWS In xlApp.workbooks(1).worksheets
xlWS.PrintOut
Next
xlApp.workbooks(1).Close False
Case "xlsm"
att.SaveAsFile objTempFolder & "\" & att.Filename
xlApp.workbooks.Open objTempFolder & "\" & att.Filename
For Each xlWS In xlApp.workbooks(1).worksheets
xlWS.PrintOut
Next
xlApp.workbooks(1).Close False
Case "doc"
att.SaveAsFile objTempFolder & "\" & att.Filename
ShellExecute 0&, "Print", objTempFolder & "\" & att.Filename, 0&, 0&, 0&
Case "pdf"
att.SaveAsFile objTempFolder & "\" & att.Filename
ShellExecute 0&, "Print", objTempFolder & "\" & att.Filename, 0&, 0&, 0&
End Select
Next
Next
xlApp.Quit
End Sub
|