Reply all by attachment name

Vijay

Member
Outlook version
Outlook 2010 64 bit
Email Account
Hi All,

my first post here,

i have this below code working great as it is searching email with subject line and replying to it.

the same task can i search by "Attachment name" and make reply ?

here is the code

Try
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace

Dim olMail As Outlook.MailItem




olApp = New Outlook.Application
olNs = olApp.GetNamespace("MAPI")
Dim Fldr As MAPIFolder


Fldr = olNs.GetDefaultFolder(OlDefaultFolders.olFolderInbox)


For Each olMail In Fldr.Items


If InStr(olMail.Submitted, TextBox1.Text) <> 0 Then
olMail.Display()



End If
Next olMail

Catch ex As System.Exception

MsgBox(Err.Description)


End Try

End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
The same solution: Within the loop through the emails, use another loop through olMail.Attachments, and search for the DisplayName of the attachment.
 

Vijay

Member
Outlook version
Outlook 2010 64 bit
Email Account
Hi Michael,
thanks for the reply, am not finding the display name for the same.. could you give me some example
 

Vijay

Member
Outlook version
Outlook 2010 64 bit
Email Account
my code is pasted in the starting of this thread.
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Pleas show your changes subject to the attachments, so we can see what's going on.
 

Vijay

Member
Outlook version
Outlook 2010 64 bit
Email Account
Try
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim oObject As Object
Dim i As Integer




olApp = New Outlook.Application
olNs = olApp.GetNamespace("MAPI")

Dim Fldr As MAPIFolder
Fldr = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
i = 1

For Each oObject In Fldr.Items

If TypeOf oObject Is Outlook.MailItem Then
olMail = CType(oObject, Outlook.MailItem)



If InStr(olMail.attachments.displayname, TextBox1.Text) <> 0 Then
olMail.Display()
i = i + 1
End If
End If


Next oObject


Catch ex As System.Exception
MsgBox(Err.Description)
End Try

End Sub


whats wrong here. ?
 

Vijay

Member
Outlook version
Outlook 2010 64 bit
Email Account
Well however i am succesfully able to display the mailitem by searching through attachment name however new issue is ...

mails getting displayed but not reply all happening.


Try
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim oObject As Object
Dim i As Integer
Dim objAtt As Outlook.Attachment


olApp = New Outlook.Application
olNs = olApp.GetNamespace("MAPI")

Dim Fldr As MAPIFolder
Fldr = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
i = 1


For Each oObject In Fldr.Items



If TypeOf oObject Is Outlook.MailItem Then
olMail = CType(oObject, Outlook.MailItem)

For Each objAtt In olMail.Attachments
If InStr(objAtt.DisplayName, TextBox1.Text) <> 0 Then
olMail.Display()
olMail.ReplyAll()

i = i + 1

End If

Next objAtt

End If

Next oObject




Catch ex As System.Exception
MsgBox(Err.Description)
End Try

End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
The ReplyAll function returns a new MailItem object. If you want to send it, call that new item`s Send procedure.
 
Top