Isaac
Lifelong Learner
- Local time
- Today, 12:51
- Joined
- Mar 14, 2017
- Messages
- 8,777
I think if you utilize If Instr(1,myMail.Body,"Text to Find")>0 , you'll have your test. And this is JUST me probably, but I think when you are newer to code, With blocks make things seem harder, not easier. Although they look neat and tidy, they make the hierarchy of objects vs. members a little bit harder to grasp (unless everything is just on one simple level), and make it a bit confusing when you need to "do" other things within the With block.It just seemed a simple thing to try to inspect an email to find if a particular text exists
You can also write that area of code as something like:
Code:
'get new info to populate email template
strFind="company"
If Instr(1,myMail.body,strFind)=0 then
strMsg = "Enter caller's company."
strInput = InputBox(Prompt:=strMsg, Title:="Leave blank if not known/relevant")
sbjtCoy = strInput
strInput = "from " & strInput
End If
myMail.HTMLBody = Replace(MyMail.HTMLBody, strFind, strInput)
Code:
strFind="company"
If Instr(1,myMail.body,strFind)=0 then
strMsg = "Enter caller's company."
strInput = InputBox(Prompt:=strMsg, Title:="Leave blank if not known/relevant")
sbjtCoy = strInput
strInput = "from " & strInput
myMail.HTMLBody = myMail.HTMLBody & vbnewline & strInput
Else
myMail.HTMLBody = myMail.HTMLBody
'unnecessary, but I added for clarification
End If