PDA

View Full Version : Move userform entry to bookmarks with different lengths



cdrunner
09-21-2016, 10:40 AM
I have a userform that passes the users entry in one text field to two different named bookmarks in a Word doc. At one bookmark I need the all the data entered, at the second bookmark I need to limited the data displaying on the form to a specific number of characters, 35 to be exact. I have looked at trim but that is for spaces. I don't want to limit the entry at the userform since I need it for one of the two bookmarks. Your guidance is appreciated.

gmaxey
09-21-2016, 11:29 AM
Dim oBM As Bookmark
Dim oRng As Range
Set oBM = ActiveDocument.Bookmarks("a")
Set oRng = oBM.Range
oRng.Text = TextBox1.Text
ActiveDocument.Bookmarks.Add "a", oRng
Set oBM = ActiveDocument.Bookmarks("b")
Set oRng = oBM.Range
If Len(TextBox1.Text) >= 35 Then
oRng.Text = Left(TextBox1.Text, 35)
Else
oRng.Text = TextBox1.Text
End If
ActiveDocument.Bookmarks.Add "b", oRng