?
Solved

Outlook.Mailitem.Body datatype

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

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
Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

 
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 70

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 70

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 70

Expert Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Suggested Courses

752 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