Home > OS >  Inserting text from VBA UserForm textbox into part of a string
Inserting text from VBA UserForm textbox into part of a string

Time:12-05

I'm new to VBA and hoping someone could help, if this might even be possible.

A date will be manually added 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 (depending on the button selected) 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 that was entered in TEXTBOX1 to appear at the end of the sentence of EXAMPLE SENTENCE 2 before the & CHR(11) &. Can anybody please help with this? Thank you!

I've tried numerous online searches to find the answer for my problem but haven't come across anything so far unfortunately.

CodePudding user response:

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