Donfernando
Donfernando

Reputation: 5

How to convert a multi line string input from an textbox (in a userform) to a single line input string (vba word)

I have created a user form on VBA (word) where the user inputs a body of multi line text into TextBox1. I wish to convert this into a single line string. I have tried the following:

'Replace method 
TextBox1.Text = TextBox1.Text.Replace what:=vbFl replacement:=""

This results in 'invalid qualifier' with regards to the .Text

'Replace function
TextBox1.Text = Replace(TextBox1.Text, vbLf, "")

This produces no error but doesn't carry out the required conversion.

Upvotes: 0

Views: 1746

Answers (1)

interesting-name-here
interesting-name-here

Reputation: 1890

In Word, you have to consider the carriage return as well. There are three ways doing it your way:

'Replace function
TextBox1.Text = Replace(TextBox1.Text, vbCr + vbLf, "")
TextBox1.Text = Replace(TextBox1.Text, Chr(10) + Chr(13), "")
TextBox1.Text = Replace(TextBox1.Text, vbCrLf, "")

Upvotes: 1

Related Questions