Capture.JPG
This code runs, and spits out the email and attachment, but keeps giving this error. Any help is appreciated.
' Script to run with an Outlook rule.
' Open Visual Basic window in Outlook,
' and paste the entirely of this script
' into the ThisOutlokkSession window
' Save the script and close=and=reopen
' Outlook to test.
Sub AttachementPrint(Item As Outlook.MailItem)
On Error GoTo OError
' This script finds the system's Temp folders,
' saves any attachments, and runs the Print
' command for that file.
Dim oFS As FileSystemObject
Dim sTempFolder As String
Set oFS = New FilesSystemObject
sTempFolder = oFS.GetSpecialFolder(TemporaryFolder)
cTmpFld = aTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
MkDir (cTmpFld)
' in the next few lines, you'll see an entry that says
' FileType = . This line gets the last 4
' characters of he file name, wich we'll use later.
Dim oAtt As Attachements
For Each oAtt In Item.Attachements
FileName = oAtt.FileName
FileType = LCase$(Right$(FileName, 4))
FullFile = cTmpFld & "" & FileName
oAtt.SaveAsFile (FullFile)
' We're using the FileType text. Note that it's the
' last 4 characters of the file name, wich is why
' - the period counts as the fourth character.
' Insert any file extensions you want printed.
Select Case FileType
Case ".pdf", ".xls", "xlsx", ".ppt", "pptx", ".doc", "docx"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(0)
Set objFolderItem = objFolder.ParseName(FullFile)
objFolderItem.InvokeVerbEx ("print")
End Select
Next oAtt
'Cleanup
If Not oFS Is Nothing Then Set oFS = Nothing
If Not objFolder Is Nothing Then Set objFolder = Nothing
If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing
If Not objShell Is Nothing Then Set objShell = Nothing
OError:
If Err <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Err.Clear
End If
Exit Sub
End Sub