PDA

View Full Version : How to copy HTML formatted mailItem.Body with line breaks to a website Textarea?



dr_patso
10-01-2012, 12:48 PM
I have a problem with this code, which copies the body in "clear text" to a text area field on a website..

The HTML E-mail looks like this
---------------------------------------------------------------------------------------------------
Try this out too.

Me
team name
phone
email
---------------------------------------------------------------------------------------------------
when I populate hte text area with objitem.body it looks like this (note the extra line breaks):
---------------------------------------------------------------------------------------------------
Try this out too.



Me

team name

phone

HYPERLINK "mailto:email"email
---------------------------------------------------------------------------------------------------
here is the code



Sub HelpdeskNewTicket()
Dim helpdeskaddress As String
Dim objMail As Outlook.MailItem
Dim strbody As String
Dim oldmsg As String
Dim senderaddress As String
Dim addresstype As Integer
Dim ie As Object
Dim sResult As String
Dim dtTimer As Date
Dim lAddTime As Long





Dim sBody As String




Set objItem = GetCurrentItem()









' Sender E=mail Address
senderaddress = objItem.SenderEmailAddress

'Searches for @ in the email address to determine if it is an exchange user
addresstype = InStr(senderaddress, "@")

' If the address is an Exchange DN use the Senders Name
If addresstype = 0 Then
senderaddress = objItem.SenderName
End If

Dim strText = objItem.Body

Const sOVIDURL As String = "website"
Const lREADYSTATE_COMPLETE As Long = 4

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate sOVIDURL

dtTimer = Now
lAddTime = TimeValue("00:00:20")

Do Until ie.readystate = lREADYSTATE_COMPLETE And Not ie.busy
DoEvents
If dtTimer + lAddTime > Now Then Exit Do
Loop

ie.document.getElementById("user").Value = "username"
ie.document.getElementById("password").Value = "password"
ie.document.forms(0).submit

Do Until ie.readystate = lREADYSTATE_COMPLETE And Not ie.busy
DoEvents
If dtTimer + lAddTime > Now Then Exit Do
Loop

ie.navigate "website"

Do Until ie.readystate = lREADYSTATE_COMPLETE And Not ie.busy
DoEvents
If dtTimer + lAddTime > Now Then Exit Do
Loop

While ie.busy
DoEvents
Wend

ie.document.getElementById("name").Value = objItem.SenderName
ie.document.getElementById("subject").Value = objItem.Subject
ie.document.getElementById("message").Value = objItem.Body


dtTimer = Now
lAddTime = TimeValue("00:00:20")
Set ie = Nothing ' If you want to close it.


'Dim PageNumber As Object


Set objItem = Nothing
Set objMail = Nothing
End Sub

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = _
objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = _
objApp.ActiveInspector.currentItem
Case Else
End Select
End Function


How do I get mailitem.body to display the HTML email's "clear text" is if I were copying and pasting it? Read the line breaks right and don't bother with HYPERLINKS, just use the text from them.

dr_patso
10-02-2012, 02:01 PM
SOLVEDEDED specific issue



If objItem.BodyFormat = olFormatHTML Then
ie.document.getElementById("message").Value = Replace(objItem.Body, vbCrLf & vbCrLf, vbCrLf)
End If
If objItem.BodyFormat = olFormatPlain Then
ie.document.getElementById("message").Value = objItem.Body
End If
If objItem.BodyFormat = olFormatRichText Then
ie.document.getElementById("message").Value = objItem.Body
End If