[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Outlook.Mailitem.Body datatype

Posted on 2011-03-15
22
Medium Priority
?
1,071 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 71

Assisted Solution

by:Qlemo
Qlemo earned 500 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 15

Accepted Solution

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

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

 
0
 
LVL 31

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 101

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 71

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 500 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 31

Assisted Solution

by:MlandaT
MlandaT earned 500 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 31

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 71

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 71

Expert Comment

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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

656 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