Solved

Outlook.Mailitem.Body datatype

Posted on 2011-03-15
22
1,059 Views
Last Modified: 2012-05-11
Hi Experts,
    I ran into a problem where after retrieving the mailitem body text, the result appears what i see isn't what i get. In my case:

Dim objOutlook As Outlook.Application
Dim oMail As Outlook.MailItem
Set oMail = Application.ActiveInspector.CurrentItem
Dim strBody As String
strBody = oMail.Body

after these codes I found strBody string is a whole line of string which looks fine to me. then i started my processing:

if strBody = "Daily" then
  i = 1
End if

For illustrating purpose, my strBody in my Email returns me "Daily" as i debug.print mailitem.body in immediate window. but when i run the if statements, it never went through 'Then'.
It turns out to me that strBody isn't just "Daily" as what i saw in immediate window.

I also did a check on mailitem.bodyformat, it is plaintext. Does anybody have a clue how do i solve this issue?
0
Comment
Question by:miketonny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +4
22 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35144292
Perhaps if you call Trim()?
strBody = oMail.Body.Trim()

Open in new window

0
 
LVL 2

Author Comment

by:miketonny
ID: 35144457
sry i forgot to mention it's in Outlook 2010 vba macro,
I tried Trim(strBody) before, it's not working as it should.
I see from immediate window strBody = "Daily",
but it just dont pass over 'Then'
0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 125 total points
ID: 35319660
Certain that there are no new lines and other "white space" involved? You would not see that in Immediate Window, and trim doesn't trim that - it only removes real spaces. Try what
   ? ">" & strBody & "<"
displays.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 15

Accepted Solution

by:
dbbishop earned 125 total points
ID: 35319661
Try:

If Left(strBody, 5) = "Daily" Then
  i = 1
End If

 
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 35319710
can you post the msg file?
0
 
LVL 2

Author Comment

by:miketonny
ID: 35320079
? ">" & strBody & "<"
>Submission from online OEM form for applying for new emailed pricelists.Logged in users details:Customer: ROS0111Contact: EGEE ENTERPRISESPricelevel: 3IP: 121.98.129.47Email: kate@egee.co.nzRequested email details:Email: kate@egee.co.nzType: XLSXFrequency: Daily
<
that's what strBody originally has.

0
 
LVL 2

Author Comment

by:miketonny
ID: 35320100
Hi dbbishop,  that actually worked, thanks.
do you mind tell me why though?
I use :
If strFrequency= "Daily" then
  intFreq = 1
Else
    intFreq = 5
End if
which is not working, but
If Left(strFrequency, 5) = "Daily" Then
    intFreq = 1
Else
    intFreq = 5
End If

this worked.
strFrequency's value is "Daily" for both cases. I'm curious why same value returns me different results
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 35320245
Apparently there is a character after Daily in the email message

0
 
LVL 15

Expert Comment

by:dbbishop
ID: 35320313
As mlmcc stated, there may be a 'control character' following the actual text. These are typically not displayable characters.

You can run a little test if you're up to it:

strBody = oMail.Body
debug.print len(strBody)
For i = 1 To Len(strBody)
    Debug.Print ASCII(MID$(strBody, i, 1)
Next i

This should give you:
68      ' D
97      ' a
105    ' i
108    ' l
121    ' y
...

Anything after the 121 is extraneous data.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 35321469
That is what I tried to express in http:#35319660 ...
0
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 125 total points
ID: 35322332
Hi, miketonny.

Trim only removes spaces.  There may be a control character in the body that you can't see.  How about using InStr to test for the presence of "Daily" in the body?
0
 
LVL 30

Assisted Solution

by:MlandaT
MlandaT earned 125 total points
ID: 35322624
you can remove all whitespace characters from the message body with this regular expression:

	strBody = oMail.Body
	Dim reg As New Regex("\s*")
	strBody = reg.Replace(strBody, "").trim()

Open in new window


That should take out all the funny invisible characters. The
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 35322632
If it is enough to just detect the presence of the word "Daily" in the body, you can even just use the Like operator...

If strFrequency Like "*Daily*" then
  intFreq = 1
Else
    intFreq = 5
End if

Open in new window

0
 
LVL 2

Author Comment

by:miketonny
ID: 35328134
Hi dibishop, you're right, i ran the test and there was a 10 & 13 after 121, so that's the carriage return and linefeed at the end of the word, I now know how to test that.
thx guys for the help, much appreciated
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 35328329
I mentioned that in http:#a35319660 ..., and have been first to do so.
0
 
LVL 2

Author Comment

by:miketonny
ID: 35328700
sry Qlemo i missed that when i tick the boxes, is there any other way to assign points?
0
 
LVL 2

Author Comment

by:miketonny
ID: 35328910
cool all set now, thanks for reminding my mistake, i just saw the reference
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 35328917
Thank you for taking the additional effort to do a fair split.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question