vijay.vizzu
Member
Hi All
I am trying to write a VBA code which can select emailid based upon filename and then send mails to the concerned person. So i am going to use Select Case Statment, but it can't work. I am unable to solve the problem as i am new to VBA. So please help to resolve my problem. I have tried a lot but can't able to resolve
[pre]
[/pre]
I am trying to write a VBA code which can select emailid based upon filename and then send mails to the concerned person. So i am going to use Select Case Statment, but it can't work. I am unable to solve the problem as i am new to VBA. So please help to resolve my problem. I have tried a lot but can't able to resolve
[pre]
Code:
Sub Createmail()
Dim OutApp As Object
Dim MailItem As Object
Dim Fso As Object
Dim myFolder As Object
Dim myFilename As Object
Dim EmailID As String
Set Fso = CreateObject("scripting.filesystemobject")
Set myFolder = Fso.getfolder("E:project")
For Each myFilename In myFolder.Files
Select Case myFilename
Case InStr(Len(myFolder), myFilename, "Man", vbBinaryCompare) > 0
EmailID = "h@ymail.com"
Case InStr(Len(myFolder), myFilename, "Ven", vbBinaryCompare) > 0
EmailID = "v@ymail.com"
Case Else
MsgBox "Not Found"
End Select
Next
Set OutApp = CreateObject("outlook.application")
Set MailItem = OutApp.createitem(0)
With MailItem
.to = EmailID
.Subject = "This is test"
.body = "Please find attachment"
.display
End With
Set OutApp = Nothing
Set MailItem = Nothing
End Sub