Consulting

Results 1 to 2 of 2

Thread: Move userform entry to bookmarks with different lengths

  1. #1
    VBAX Regular
    Joined
    Mar 2012
    Posts
    12
    Location

    Move userform entry to bookmarks with different lengths

    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.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •