I want to enter each element of an array onto a new line in multiline textbox on a userform. I have the Multiline and EnterKeyBehaviour of the textbox set to True.
The code below will enter the array elements but after entered they are then overwritten by the next element.
For i = LBound(clipArray) To UBound(clipArray)
frmMyForm.txtBox.Text = clipArray(i)
Next
I have tried variations like below (with vbCr, vbCrLf etc) but still does not work.
frmMyForm.txtBox.Text = clipArray(i, vbNewLine)
How can I fix?
Please, use:
frmMyForm.txtBox.Text = Join(clipArray, vbLf)
Related
I Want to add the line from the text box to a list box if it contains a word from words.
This code introduces my result into the textbox, I want it in a textbox line or in a listbox line.
So, TempTextBox will have to be a textbox line or a listbox line so I will not create too many textboxes. How can I improve the code?
If TextBox1.Lines(i).Contains(word) Then
found = True
Dim tempTextBox As TextBox = CType(Me.Controls("CheckVar" & i.ToString), TextBox)
On Error Resume Next
If TextBox2.Lines(i).Contains(word) Then
If tempTextBox.Text.Contains(word) Then
Else
tempTextBox.Text = tempTextBox.Text + " " + TxtbValAfterCompar.Text()
End If
Else
End If
End If
I have a text box in a Word 2016 document. This is not a TextBox form object but a normal Text Box that you insert from the Insert tab here:
I am trying to check if it is empty when the document is opened. For the life of me I cannot figure out how to do this. I have tried all of the following:
If (Len(ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes("Text Box 2").TextFrame.TextRange.Text & vbNullString) = 0) Then
If (IsNull(ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes("Text Box 2").TextFrame.TextRange.Text)) Then
If (LTrim(RTrim(ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes("Text Box 2").TextFrame.TextRange.Text)) = "") Then
If (ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes("Text Box 2").TextFrame.TextRange.Text = "") Then
None of these return true when the text box is empty? This is the text box:
It seems that the text box always contains a paragraph marker (which I can't delete). This is what the VBA watch shows:
Watch : : ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes("Text Box 2").TextFrame.TextRange.Text : "
" : String : ThisDocument.Document_Open
Note that the watch is two separate lines which makes me think that there's CRLF or something in there?
There is always a paragraph break in an otherwise empty textbox. Accordingly, you could use something along the lines of:
Private Sub Document_Open()
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes("Text Box 2")
If Not .TextFrame Is Nothing Then
If Trim(.TextFrame.TextRange.Text) = vbCr Then
MsgBox "Empty Text Range"
End If
Else
MsgBox "No Text Range"
End If
End With
End Sub
Can I loop through a Textbox for each line entered and format it? For example if the user entered:
Text1
Text2
I would like to output it as in a single line.
'Text1','Text2'
Also would be awesome if you can get the last comma to not display.
This is what you really need
Add a textbox to your sheet
Add this code on TextBox1_Change() event
Dim mystr
mystr = Split(Sheet1.TextBox1.Text, vbCrLf)
Sheet1.Range("A1") = "'" & Join(mystr, "','") & "'"
Right click to textbox and enable multiline option
Control + Enter to change line inside textbox
And you have the result that you want:
Hey fellow Stackoverflow users,
i'm trying to create a text editor with HTML tag functions (for export) and can't get a solution working. Therefor i created a textbox where the user should be able to insert the text. For this insert function i need the in the title described function to delete the selected text (only the selected text, the text around it stays) inside the textbox. Even SendKeys won't function right.
Please let me know if anyone got an idea, thanks upfront!
EDIT: Here's the corrected code for the bold button with maintextbox as textbox for the user's text:
Private Sub BoldButton_Click()
If maintextbox.SelLength = 0 Then
MsgBox ("Please highlight the text you want to edit!")
Else
SelectionText = maintextbox.SelText MsgBox ("SelText: " & SelectionText)
maintextbox.SelText = "<b>" & _
SelectionText & _
"</b>"
End If
End Sub
Simply:
TextBox.SelText = ""
The .Sel* methods all relate to the text currently selected within the control. SelText = "" replaces the current selection with nothing, thereby deleting it whilst preserving the surrounding unselected text.
I have a multi-line textbox textbox1 and want to add the content to listbox1, but before each item I need to add "wordX=" where "X" is the item number.
Example of textbox1:
bob
gear
dog
etc.
Then listbox1 should have:
word1=bob
word2=gear
word3=dog
etc.
Currently I am using the line below to copy the textbox3 content to listbox1 but can't find how to add "word" and the proper number.
ListBox1.Items.AddRange(TextBox3.Text.Split(vbNewLine))
This is what I used to complete what you wanted.
Dim tbLines As String() = TextBox1.Text.Split(vbNewLine)
ListBox1.Items.Clear()
For i As Integer = 1 To tbLines.Length
ListBox1.Items.AddRange({"word" & i & "=" & tbLines(i - 1).Trim})
Next
I split the text box using the vbNewLine separator as you did. I then go through each index in that array to concatenate the string "word" with the i (current index) integer. I finish off with concatenating the "=" as well as the trimmed value in the listbox.