PDA

View Full Version : VBA replies twice with one .send



Maxx_Daddy
02-06-2014, 11:11 AM
This code does exactly what I need it to do, but I want to be able to send a reply to the sender to let them know we got the photos, it works great but the thing sends two replies, what's worse is the due to the .body being unreadable, i built a catch to resend the email with the body as the subject and it does that 4 times. any ideas?



Public Sub piclandfolder(itm As Outlook.MailItem) Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "\\my folder thingy\Photo Share\current week"
Dim dateFormat As String
dateFormat = Format(itm.ReceivedTime, "MM-DD-YY ")
Dim pics As String
pics = "pics at dumbemail"
TextBody = itm.Body
Dim sender As String
sender = itm.SenderEmailAddress
Dim count As Integer
count = 1

For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & itm.Subject & "-" & dateFormat & "-" & "(" & count & ")" & ".jpg"
count = count + 1

Next
'this is my catch, i try to save the photos as the subject line, if there is no subject (say from a text message) then I forward the message to myself with the body as the subject, this is because I couldn't find a way to use the itm.body as part of the saveas.
If itm.Subject = Empty Then
Set itmf = itm.Forward
With itmf
.To = "pics at dumbemail"
.Subject = itm.Body
.Send
End With
itm.Delete
Dim msgf As Outlook.MailItem
Set msgf = Application.CreateItem(olMailItem)
msgf.To = sender
msgf.Body = "thank you for your pictures, please put your door description in the 'subject' when sending photos in, thanks!!"
msgf.Send
Set msgf = Nothing
Exit Sub


Else
MsgBox "you have a new picture e-mail from " & sender
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
With msg
.To = sender
.Subject = itm.Body
.Body = "thank you for your " & itm.Subject & " pictures, have a terrific day!!"
.Send
End With
Set msg = Nothing
End If
End Sub


thanks!!