View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Cleaning text boxes

Hi Jason,

Try:

original_text = Application.Clean(original_text)


---
Regards,
Norman



"jasonsweeney"
wrote in message
news:jasonsweeney.1x6n2d_1129781113.3461@excelforu m-nospam.com...

I need to "scrub" text entered into a text box. By "scrub" I mean that
I want to remove certain unwanted characters and formatting. My code
(below) effectively removes all unwanted characters, but certain
carriage returns, etc., are not removed. Any suggestions?

To test the code, I go to the following website:
http://shakespeare.about.com/library.../aa011801a.htm, press
cntrl-A to select all text, copy, and then paste from clipboard into a
textbox in a userform. This is first few lines of the output:

" You are heAboutHomework HelpShakespeareHomework
HelpShakespeareEssentialsShakespeare FAQsQuotationsSoliloquy
AnalysisElizabethan Glossary Shakespeare TimelineShakespeare
OffersShakespeare Plays Shakespeare Movie BBC Shakespeare Shakespeare
Videos William Shakespeare What are offers?Articles & ResourcesStudent
"

Note that the there is a hard-return after "Homework" on the first
line. I need to remove this. The text needs to end up as one large
paragraph with no carriage returns, paragraphs breaks, etc....
___________________________
The code (userform, textbox1,commandbutton1)

Private Sub CommandButton1_Click()
Dim original_text, Revised_text, chk_char, firsts_string As String
Dim Character_count As Integer
original_text = TextBox1.Value
'
'
'Clean Text
Character_count = Len(original_text)
For i = 1 To Character_count
chk_char = Asc(Mid(original_text, i, 1))
If chk_char 31 And chk_char < 126 Then
Revised_text = Revised_text & Mid(original_text, i, 1)
End If
Next i
TextBox1.Value = Revised_text

End Sub

___________________________________


--
jasonsweeney
------------------------------------------------------------------------
jasonsweeney's Profile:
http://www.excelforum.com/member.php...fo&userid=5222
View this thread: http://www.excelforum.com/showthread...hreadid=477772