Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    May 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reading individual lines in textbox (Word 9.0 sp3)

    Hi,

    I made a form in VBA which contains a textbox. In the textbox you can fill in names, divided bij returns. I can read the total amount of lines (with linecount) , but want to read the individual lines as well and store the values in a variable.

    How do i do this?

    Thanks in advance,

    Paul

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: reading individual lines in textbox (Word 9.0 sp3)

    Welcome to Woody's Lounge!

    Do you mean a text box on a userform? You can use the Split function to split its value into separate lines and store the individual lines in an array:

    Dim strArr() As String
    Dim i As Integer
    strVal = Me.TextBox1
    strArr = Split(Me.TextBox1, vbCrLf)
    For i = LBound(strArr) To UBound(strArr)
    MsgBox strArr(i)
    Next i

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: reading individual lines in textbox (Word 9.0

    In this line, you need to use the interior loop counter "a" instead of the exterior loop counter "i":

    <code> .TypeText Text:=StrNamen(i) 'namen op doc printen</code>

  4. #4
    New Lounger
    Join Date
    May 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: reading individual lines in textbox (Word 9.0

    <P ID="edit" class=small>(Edited by jscher2000 on 30-May-08 11:22. Added
    Code:
     and
    tags and some [tab]s in the code for improved readability.
    )</P>Hans,

    Thank you I can see what this code does (repeated message boxes) but i can't seem to get it to work properly. I want to print a number of documents (exam forms), the number depending on the number of participants in the exam and to print the names of each participant on each separate document. What happens is that the correct number of docs is produced with the correct names on them but that all the names are placed 'i' times. Is it possible to print each name only once?

    Thanks in advance

    Paul

    Here is the code iI use:

    <code>If Me.ChkPVB_MI_KT1 Then
    For i = 0 To IntAantal - 1 'aantal documenten invoegen adhv aantal deelnemers
    strFilename = StrPath & "subdoc_Dagdraaiboek_Assessoren_56098_2007wk25.doc "
    VoegDocumentIn
    StrNamen = Split(Me.TxtNaamDeelnemers, vbCrLf) 'namen uitlezen
    For a = LBound(StrNamen) To UBound(StrNamen)
    With Selection
    .EndKey Unit:=wdStory, Extend:=wdMove
    .MoveUp Unit:=wdLine, Count:=15, Extend:=wdMove
    .TypeText Text:=StrNamen(i) 'namen op doc printen
    End With
    Next a
    Next i</code>

  5. #5
    New Lounger
    Join Date
    May 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: reading individual lines in textbox (Word 9.0

    Dear jscher,

    Thanks for your comment but Itried this already, the result being that it printed each name "a" times on each document (So, in case of 5 documents, each name 5 times like JohnJohnJohnJohnJohn)

    The other possibility was to get all different names on each document like JohnPeterPaulLucyEdith

    The solution was that I removed the inner loop altogether, now it works fine.

    Thanks fot thinking with me,

    Paul

  6. #6
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    667
    Thanks
    3
    Thanked 19 Times in 18 Posts

    Re: reading individual lines in textbox (Word 9.0

    [Edited to correct error in transcription of code... ooops! <img src=/S/blush.gif border=0 alt=blush width=15 height=15> )

    You don't need two loops. Try this:

    <pre>If Me.ChkPVB_MI_KT1 Then

    strArr = Split(Me.TextBox1, vbCrLf) ' fill the array

    For i = 0 To IntAantal - 1 ' do this for the number of names
    strFilename = StrPath & "subdoc_Dagdraaiboek_Assessoren_56098_2007wk25.doc "
    Selection.InsertFile strFilename ' VoegDocumentIn
    With Selection
    .EndKey Unit:=wdStory, Extend:=wdMove
    .MoveUp Unit:=wdLine, Count:=15, Extend:=wdMove
    .TypeText Text:=strArr(i) 'namen op doc printen
    End With
    Next i
    </pre>


    Does this do it for you? With the exception of VoegDocumentIn <img src=/S/grin.gif border=0 alt=grin width=15 height=15> I was able to make this work for me.

    Best, Kim

  7. #7
    New Lounger
    Join Date
    May 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: reading individual lines in textbox (Word 9.0

    Dear Kim,

    You are right, I don't need the inner loop. It works fine now, thanks. I will post my final code when i am finished. The end result will be that you can create personalized (named) docs for a random number of people , who perform different roles and so get a set of different (although not always) documents.

    Thanks,

    Paul

Posting Permissions

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