Solved

VB.NET/Outlook Message Display Issue

Posted on 2008-10-13
10
594 Views
Last Modified: 2012-05-05
Hello everyone.

I was working on a very complex macro in VBA using Outlook 2007's macro editor, but then realized the project was more suited for a standalone executable. Feeling working on this in VBA was too outdated, I switched over to VB.NET (on VS Express 2008), and began porting my code.

Everything seems to be working fine as 90% of the code is simple logic, not playing around with Outlook. The one problem I am having is involving code that reads HTML from a file & places it in the HTMLBody of a new Outlook message.

When using VBA code with what appears to be the exact same functionality (see below), I get different results. When I scan the HTML file's text & put it in the messages HTML body using VBA everything ends up fine (images intact, no weird formatting errors).

When I scan the same HTML file using VB.NET code & fill in the HTML body, I get strange formatting errors that are black diamond shaped boxes with question marks inside.  Up until today I was also getting errors stating ""The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, then open the file again. If the red x still appears, you may have to delete the image and then insert it again."  Here's a screenshot of what I'm talking about... http://www.tneus.com/images/screenshot.jpg

Yet when I test the same thing again in VBA (after receiving this error), everything once again still works fine.

The HTML template I am using was exported from an OFT file in Outlook, so there is some strange markup that's not in regular HTML files. I don't know why or how this would affect the display of information though, if everything is working fine with one method.

I've asked this question on several forums (and waited about a week for responses) and have had zero help.  Any help would be GREATLY appreciated, as this is immensely frustrating.

Thank you.
0
Comment
Question by:tnesupport
[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
  • 5
  • 5
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22709461
Regarding the diamonds with questions marks, if you notice that the line "Don't Miss Out" has that diamond with question mark in place of ', you would easily understand the source of the problem. In VB.NET, ' is used to comment the code. So anything beyond ' is considered a commend. Try Replacing those characters with chr() function by using appropriate numeric value such as 13 is for vbcrlf.
The formatting may be going wrong because of this basic issue. I think if you solve this problem then other problems would be solved automatically. If not, do come back.
0
 
LVL 1

Author Comment

by:tnesupport
ID: 22712396
This may be part of the problem, but your suggestion pointed me in the right direction.  Some diamonds are being caused by whitespace..for example..

<p><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
      "Verdana","sans-serif";mso-bidi-font-family:Arial;color:#666666;
      mso-bidi-font-weight:bold'>Call us today to register for this exciting
      preview event. We look forward to seeing you there!<span
      style='mso-spacerun:yes'>  </span><o:p></o:p></span></p>

The whitespace in between <span style='mso-spacerun:yes'>  </span> those two tags is causing this to appear.

This seems like an encoding issue to me but i have 0 experience with this subject...do you have any ideas?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22712440
I would suggest you to first replace the single quotes as the span has many of these in pairs for styles. If that does not help then look for other problems. The reason is that i send HTML based emails from VB.NET and never had a problem.

Also, never saw this tag before
<o:p></o:p>
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Author Comment

by:tnesupport
ID: 22712509
I understand..here's some more info...When I change my streamreader's encoding to ANSI, there is no longer any black diamonds but all the images will not show ("The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, then open the file again. If the red x still appears, you may have to delete the image and then insert it again." )

The tag <o:p></o:p> is something with Microsoft Office..as the HTML file was exported from OFT file.
0
 
LVL 1

Author Comment

by:tnesupport
ID: 22712529
Excuse me, when I re-save the file in notepad using UTF8 encoding, and set my stream reader to UTF8 encoding it works...does anyone by any chance know the default encoding when you save a HTML file from outlook?  Does it use the system's default encoding?  Or does anyone know the default encoding of the Scripting.FileSystemObject..?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 22712535
Did you try other encodings such as UTF?
0
 
LVL 1

Author Comment

by:tnesupport
ID: 22712571
This was the solution..the encoding for stream reader needed to be set to Encoding.Default...thanks a lot for helping me see what the problem was here CodeCruiser :).
0
 
LVL 1

Author Closing Comment

by:tnesupport
ID: 31505607
Thanks a lot man!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22712602
The encoding can be changed for outgoing messages through Tools->Options Mail Format tab, and International Options button. I think when saving messages as HTML, the source encoding is used.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22712620
Happy that the problem is sorted.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

724 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