Want to extract string between comma character in a string

Hi, can someone help me with code for a loop? I’m trying to write a loop that will look at a string that I have in the Keywords of a report and set a variable to the result.

Example:
Say my string is: “9,4,10” in Keywords. I want to loop thru this string and set a variable to the numbers it gets. (the comma is the seperator) So, the first loop will return 9, the 2nd loop will return 4, the 3rd loop will return 10. I want to use this to set some parameters. I’ll convert it to a number after I retrieve it. I’ve been trying InStr with a comma as my value but not having much luck…

A basic example:
Dim myReport As Document
Dim strKeywordCopies As String
Dim strCopy as String

Set myReport = ThisDocument
strKeywordCopies = myReport.Keywords

What I want to happen…

Start loop
strCopy = 9
repeat loop
strCopy = 4
repeat loop
strCopy = 10

Any help is appreciated…

thanks!


nonyup (BOB member since 2008-01-07)

Sub duh()
    Dim Keywords As String
    Dim looper As Variant
    
    Keywords = "5,27,34343,2"
    
    Dim splitList() As String
    splitList = Split(Keywords, ",")
    
    For Each looper In splitList
        Debug.Print looper
    Next
End Sub

Joe


joepeters :us: (BOB member since 2002-08-29)

Excellent, thanks! I never heard of the split command…


nonyup (BOB member since 2008-01-07)