none
split textbox input and post it in Word bookmarks RRS feed

  • Question

  • Heya,

    I`ve come upon a problem i cant seem to solve.

    I want is to get: 

    string = "1,2,3,4,5"

    to a list like this:
    1
    2
    3
    4
    5

    that gets posted to a bookmark in my word document.

    But it seems that vbCrLf gets recognized as bookmark end since i get an error after the first time it looped.

    The code i have until now:

    Set oRng = oBMs("bijlage").Range
    TextBox13.Multiline = True
    oRng.Text = Me.TextBox13
    
    Dim a_strTemp() As String
    Dim strTemp As String
    strTemp = oRng.Text
    a_strTemp = Split(strTemp, ",")
    
    Dim intCounter As Integer
    strTemp = a_strTemp(0) & vbCrLf
    For intCounter = 1 To UBound(a_strTemp)
     strTemp = strTemp & a_strTemp(intCounter) & vbCrLf
     oRng = strTemp
    Next intCounter
    
    ActiveDocument.Bookmarks.Add "bijlage", oRng

    it may be a solution to loop the bookmark with the values and create multiple bookmarks the get posted under eachother but then the word document wil get a mess after a while so i would like to prevent that.

    I Hope someone could help me out or give me a push in the right direction since i`m new to VBA

    Thursday, April 18, 2013 7:36 AM

All replies

  • I don't understand the exact meaning of this code: do you want a bookmark that includes line 1 to 5, or word 1 to 5, ... ?
    Thursday, April 18, 2013 2:03 PM
  • Hi

    Why can't you specify the Range's value at the end of the Loop

    Instead of

    oRng = strTemp
    Next intCounter


    Can you try this

    Next intCounter
    oRng.Text = strTemp
    

    Cheers

    Shasur


    http://www.vbadud.blogspot.com http://www.dotnetdud.blogspot.com

    Sunday, April 21, 2013 3:06 AM
  • Change the code as follows:

    Dim oBMs As Bookmarks
    Dim oRng As Range
    Dim a_strTemp() As String
    Dim strTemp As String
    Dim intCounter As Integer

    Set oBMs = ActiveDocument.Bookmarks
    Set oRng = oBMs("bijlage").Range

    a_strTemp = Split(TextBox13.Text, ",")
    strTemp = a_strTemp(0) & vbCr

    For intCounter = 1 To UBound(a_strTemp)
     strTemp = strTemp & a_strTemp(intCounter) & vbCr
    Next intCounter

    oRng.Text = strTemp
    ActiveDocument.Bookmarks.Add "bijlage", oRng


    Graham Mayor - Word MVP
    www.gmayor.com

    Sunday, April 21, 2013 7:12 AM