Search code examples
vbams-wordtextboxuserform

Inserting text from VBA UserForm textbox into part of a string


A date will be entered by the user into UserForm TEXTBOX1 which will be placed at a bookmark in the document.

.Bookmarks("BOOKMARK1").Range _
.InsertBefore TEXTBOX1

I have option buttons for the user to select, which will place specific text into the document as follows:

Private Sub OptionButton2_Click()
If Me.OptionButton2.Value = True Then
    Set oRng = ActiveDocument.Bookmarks("BOOKMARK2").Range
    oRng.Text = "EXAMPLE SENTENCE 1" & Chr(11) & Chr(9) & _
                "EXAMPLE SENTENCE 2" & Chr(11) & _
                "EXAMPLE SENTENCE 3" & vbNewLine & " "
    ActiveDocument.Bookmarks.Add "BOOKMARK2", oRng
End If
End Sub

I am trying to get the date in TEXTBOX1 to appear at the end of "EXAMPLE SENTENCE 2" before the & CHR(11) &.


Solution

  • "EXAMPLE SENTENCE 2" & TEXTBOX1.Text & Chr(11)