dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Nov 9, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Transfer Data from a RichTextBox Control to an Outlook Message


When automating Outlook from a VB application, I needed to find a way to transfer data from a RichTextBox control to an Outlook message. Unfortunately using Clipboard.SetText and Clipboard.GetText did not save the formatting of the entered text. However, I found the best way to transfer formatted text from a RichTextBox control to an Outlook message was to use "Sendkeys" to simulate Ctrl + C and Ctrl + V for copying and pasting (respectively).

This code assumes a project reference to the Outlook Object Library. My RichTextBox Control is named rtfData:
 
	Dim objOutlook As New Outlook.Application
	Dim objOutlookMsg As Outlook.MailItem
	Set objOutlookMsg = objOutlook.CreateItem(0)

	objOutlookMsg.BCC = "toanyone@anywhere.com"
        	objOutlookMsg.To = "anyone@anywhere.net"
       	objOutlookMsg.Subject = Form1.Text1.Text
            
	Clipboard.Clear
            rtfData.SelStart = "0"
            rtfData.SelLength = Len(rtfData.Text)
            rtfData.SetFocus
            
            SendKeys "^c", True      'copy text
            Me.Hide
            objOutlookMsg.Display  'display Outlook 
message
            SendKeys "^v", True    ' paste text
            Me.Show

The above code will paste all text from the RichTextBox control to the Outlook Message and will preserve all formatting.
Dan Quick
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date