-
June 9th, 2009, 11:14 AM
#1
Formatting text before sending to clipboard
I build up a text string in VB and then I want to send it to the Clipboard so that I can paste it in the body of an email. How do I go about to format (e.g. bold, underline and colored text) that text in the string in VB so that the formatting will be pasted in the email if possible.
Any pointers appreciated.
-
June 9th, 2009, 05:50 PM
#2
Re: Formatting text before sending to clipboard
Use a Rich Text Box, which is the only text control that allows formatted text to be mixed. You can have a colored font in a textbox, but not two in the same textbox
An RTB can alternate whatever you want.
-
June 11th, 2009, 03:12 PM
#3
Re: Formatting text before sending to clipboard
Most of the information in the string I'm building comes from databases. I then copy the string to the clipboard so I can paste it in the email. Currently I then format the text in the email to show the bold and underline etc.
I wanted to build the string already formatted before sending it to the clipboard. If I use a RTB, wouldn't I still need to format the text manually before sending it to the clipboard? Can the string be formatted programmatically in the RTB? I've never used a RTB before
I will have a look at the RTB and see if it could work for what I want to do.
-
June 11th, 2009, 06:23 PM
#4
Re: Formatting text before sending to clipboard
I've created a .RTF file that was just a table with about 40 fields (made in Word), and filled, using [1] ... [41] in each of the boxes that I wanted to fill in with fields. I filled in the other fields with fixed text.
It's not that hard to format on the fly, after that.
Code:
.Find "[Text]"
.SelText = "" & vbCrLf
.SelFontSize = 14
.SelText = Trim(Line1) & vbCrLf
.SelFontSize = 14
.SelText = Trim(Line2) & vbCrLf
.Find Trim(Line1)
.SelAlignment = rtfCenter
.SelStart = 0
.Find "Glass Block Panel Invoice"
.SelBold = True
.SelStart = 0
-
June 13th, 2009, 02:47 AM
#5
Re: Formatting text before sending to clipboard
I can get the text formatted in the RTB programmatically. The text in the RTB looks like this after I formatted it:
This is the text in the richtextbox. This text I want bold. And this text I want underlined.
When sending it to the clipboard with:
Code:
Clipboard.Clear
Clipboard.SetText RichTextBox1.Text
it gets pasted in the email without any formatting:
This is the text in the richtextbox. This text I want bold. And this text I want underlined.
When sending it to the clipboard with:
Code:
Clipboard.Clear
Clipboard.SetText RichTextBox1.TextRTF
This is what is pasted in the email:
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang7177\f0\fs17 This is the text in the richtextbox. \b This text I want bold.\b0 \ul And this text I want underlined\ulnone .
\par }
So it seems that the RTB is not going to work or I'm missing something. I think the format I need should be HTML but I have no idea how this works.
Last edited by Bezzie; June 13th, 2009 at 02:54 AM.
-
June 13th, 2009, 06:35 PM
#6
Re: Formatting text before sending to clipboard
You can paste formatted text into a RTB, but gettext is text
-
June 15th, 2009, 11:58 PM
#7
Re: Formatting text before sending to clipboard
Email can paste most rich text and preserve formatting.
You are failing to set the clipboard get text to the Rich Text format. So, by default your are getting the ANSI text for the RTF code. To set the text to RTF try:
Clipboard.SetText Richtextbox1.SelRTF, vbCFRTF
See the VB6 help file for clipboard formats, etc.
-
June 18th, 2009, 03:03 PM
#8
Re: Formatting text before sending to clipboard
If I use Clipboard.SetText Richtextbox1.SelRTF, vbCFRTF and try to paste into the email, nothing gets pasted. Leaving out the vbCFRTF gets the string pasted with all the RTF codes as below:
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang7177\f0\fs17 This is the text in the richtextbox. \b This text I want bold.\b0 \ul And this text I want underlined\ulnone .
\par }
Could the problem be with the Thunderbird email program?
-
June 18th, 2009, 05:39 PM
#9
Re: Formatting text before sending to clipboard
Should have said that from the beginning. That could be, as most email programs do HTML, not RTF. Microsoft Outlook does both
-
June 19th, 2009, 01:23 AM
#10
Re: Formatting text before sending to clipboard
That's got to be it. Can't test Thunderbird... don't use it. It works fine both in Outlook and Outlook Express and Vista Mail.
-
June 23rd, 2009, 01:36 AM
#11
Re: Formatting text before sending to clipboard
Is there a way to build a HTML string then?
-
June 23rd, 2009, 02:21 AM
#12
Re: Formatting text before sending to clipboard
Sure. It helps if you know it though... http://www.w3schools.com/
-
June 28th, 2009, 09:41 AM
#13
Re: Formatting text before sending to clipboard
Thanks. I'll look into it and see if I can get it figured out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|