Reputation: 826
I have a userform which contains some textboxes and a button.
when button is pressed it insert text at the end of the document. however I need to insert the text as following format:
the following code does insert the text but not formatted as required. how do I insert the text with least code possible?
Private Sub CommandButton2_Click()
Dim CR As Range
Selection.EndKey wdStory
Set CR = Selection.Range
CR.Text = vbCr & TextBox1.Text _
& vbCr & TextBox2.Text _
& vbCr & TextBox3.Text & " at " & TextBox4.Text
End Sub
Possible formatting:
Upvotes: 1
Views: 536
Reputation: 5386
FINAL EDIT - two lines of code to add
If you truly want to make the new code as short as possible
CR.Paragraphs(CR.Paragraphs.Count - 2).Range.Sentences(1).Font.Bold = True
CR.Paragraphs(CR.Paragraphs.Count - 1).Range.Hyperlinks.Add _
CR.Paragraphs(CR.Paragraphs.Count - 1).Range, _
CR.Paragraphs(CR.Paragraphs.Count - 1).Range.Text
Upvotes: 1
Reputation: 13505
For example:
With ActiveDocument.Range
With .Characters.Last
.Style = wdStyleStrong
.Text = TextBox1.Text & vbCr
End With
.Characters.Last.Font.Reset
.Hyperlinks.Add Anchor:=.Characters.Last, Address:=TextBox2.Text
.Characters.Last.Text = vbCr & TextBox3.Text & " at " & TextBox4.Text
End With
Upvotes: 1