Excel textbox formated text to Htmlbody convert - vba

I need to send text from Excel textbox with HTMLBODY. So when i send it as
.HTMLBody = ThisWorkbook.Worksheets("info").Shapes("TextBox 1").TextFrame2.TextRange.Characters.Text
Email comes without formating.
So how to convert textbox to Html source? Or how to get data from html file to .HTMLBody?

Ron de Bruin's website has some great stuff on sending HTML emails. Look on this page for the RangetoHTML function.

Related

Combining Rich Text Content Control Content in MS Word using VBA

I'm trying to create a form for a non-technical user in MS Word to capture some text content in MS Word. This word doc consists of several rich text content controls where the user will type in or paste in some formatted data (bold, underlined, links, ...).
Once they get all the content entered into these various content controls I'm trying to make it easy for them to combine them together to paste in a consistent order into some podcast show notes which is in an HTML form.
So basically, I want to take three rich text content controls that have formatted data in them, combine them together into one formatted piece of content, and then copy it to the clipboard so they can then go to this web form, paste it in, and do some minor cleanup. The problem is that whenever I try to combine the RTF content it loses the formatting.
The only way I seem to be able to keep the formatting is if I copy the range object and then paste it. However, this doesn't paste just the formatted text. It pastes the whole rich text content control.
I've tried creating a blank RTF field at the bottom of the Word doc to combine everything in but I just can't figure it out. I wouldn't think this would be rocket science.
Being none of the code I've tried works and keeps the formatting I"m not sure if posting it here will do any good. Here's how I'm getting the value of the text object:
ActiveDocument.SelectContentControlsByTitle("txtShowNotes").Item(1).Range.Text
tried this:
ActiveDocument.SelectContentControlsByTitle("txtShowNotes").Item(1).Range.Copy
ActiveDocument.SelectContentControlsByTitle("txtCombinedContentSection").Item(1).Range.Paste
but this copies the whole RTF and not just the text.
Try something based on:
Sub Demo()
Dim Rng As Range
With ActiveDocument
Set Rng = .SelectContentControlsByTitle("txtCombinedContentSection").Item(1).Range
Rng.FormattedText = _
.SelectContentControlsByTitle("txtShowNotes").Item(1).Range.FormattedText
Rng.InsertAfter vbCr & vbCr
Rng.Characters.Last.FormattedText = _
.SelectContentControlsByTitle("txtShowNotes").Item(2).Range.FormattedText
End With
End Sub

Outlook code for both plain text and html format

Some people advice that it is good idea to sent an e-mail in both format html and plain text together in the same e-mail body as following link explains.
https://litmus.com/blog/reach-more-people-and-improve-your-spam-score-why-multi-part-email-is-important
You can see four code options below.
.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
.BodyFormat = Outlook.OlBodyFormat.olFormatPlain
.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
.BodyFormat = Outlook.OlBodyFormat.olFormatUnspecified
You are able to select one option as following picture shows.
http://www.rocketseed.com/wp-content/uploads/2013/07/Outlook-2010-HTML.jpg
How to sent mixed formatted e-mails even your code must include one option?
I need vb.net code for this.
That link does not apply to Outlook: when a message is saved (or sent) all 3 flavors of the message body (plain, HTML, RTF) are synchronized. You cannot send a message from Outlook with either flavor out of sync. You can send plain text messages, html/plain, or RTF (winmail.dat), but you cannot send with plain text body out of sync of the HTML body.

vb parse word from clipboard into html

I want to copy some word text with tables, links and images and paste it into a rich textbox in my vb project. Where I want to parse it to html.
The Questenion is, how can access the copied word in the clipboard. Using
My.Computer.Clipboard.GetText()
just returns text, without the structure for links, tables or images. But there have to be a way to access it, because my rich textbox seems to know the word format. When I paste it into it, tables, images and links are also displayed in there.
You can try to specify text format in GetText's parameter as follow :
Dim htmlText As String = Clipboard.GetText(TextDataFormat.Html)

outlook 2007 - is there a way to get the formatted text from an Appointmentitem?

I'm trying to get the formatted text of the appointment item, I've searched everywhere and most places suggest getting the word document of the appointment item :
Word.Document wd = (Word.Document) (item as Outlook.AppointmentItem).GetInspector.WordEditor;
So I do that and I get the word document. But no where does it tell you what to actually do with this word document once you get it. How do I get the formatted text from the word document now?
UPDATE:
To anyone else searching for this answer in the future. I figured out how to do this in ol2007
1) First have have to get the word document from the appoint item via the WordEditor variable.
2) Then you have to use the select and copy functions from the word document to copy the RTF text into your clipboard.
3) make a richtextbox and use the richtextboc paste function to paste whats in the clipboard into your richtextbox.
4) now from the richtextbox you can access the .Rtf function which will now give you the RTF of the appointmentItem.
From my searching this method is the easiest way but you have to take over the clipboard which isn't ideal. There is a second way that I read about that is to save the word document in step 1 into an actually RTF file on your computer and then read in that RTF file.
and third way I suppose to do it would be to parse out the word document in step 1 using the Range.FormattedText function.
UPDATE: To anyone else searching for this answer in the future. I figured out how to do this in ol2007
1) First have have to get the word document from the appoint item via the WordEditor variable.
2) Then you have to use the select and copy functions from the word document to copy the RTF text into your clipboard.
3) make a richtextbox and use the richtextboc paste function to paste whats in the clipboard into your richtextbox.
4) now from the richtextbox you can access the .Rtf function which will now give you the RTF of the appointmentItem.
From my searching this method is the easiest way but you have to take over the clipboard which isn't ideal. There is a second way that I read about that is to save the word document in step 1 into an actually RTF file on your computer and then read in that RTF file.
and third way I suppose to do it would be to parse out the word document in step 1 using the Range.FormattedText function.

Outlook 2007 vsto send email with HTML content

I am developing the addin for the outlook 2007 using VSTO. One of the function is to capture the send event, then force convert the email format to HTML and then insert a link to the bottom of the email message content. Following is my code to convert the email content to html format:
mailItem.BodyFormat = OlBodyFormat.olFormatHTML;
string link = generateLink();
mailItem.Body += link;
However, when the email was recevied, it is not appear in the HTML format
What's wrong with the above code for making email as HTML?
Thank ~~
Patrick
You have to set mailItem.HTMLBody instead of mailItem.Body to use HTML.