posting this here cuz the outlook programing group is very inactive...
hopefully with how active you guys are you can help! I apologize in advance for posting an outlook vba question in an excel vba group.
I've got this loop that automatically detects for pdf file attachments in a selected range of email items, saves them to Temp so that I am able to then run a shell to print them. Since sometimes there ARENT pdf attachments, I want to only have the flag status change to complete if the e-mail has a pdf attachment. logically, where I have the flagstatus event occur in my loop makes sense to me, but it only changes the flagstatus for the first item in my selection. Here's to hoping someone smarter than me can figure out what's going on here.
Public Sub SaveandPrintAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strExePath As String
' Get the path to your My Documents folder
strFolderpath = "c:\temp\"
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
' Set the Attachment folder. (Folder must exist.)
strFolderpath = strFolderpath
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount 0 Then
For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName
If Right(strFile, 3) = "pdf" Then
strFile = strFolderpath & strFile
objAttachments.Item(i).SaveAsFile strFile
'use ShellExecute to open the file
'this may not work with zip extension if you use Compressed folders
ShellExecute 0, "print", strFile, vbNullString, vbNullString, 0
objMsg.FlagStatus = olFlagComplete
End If
Next
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
|