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


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

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