可以使用InStr函数查找你读取的每一行中的‘,’逗号
然后结合使用Left或Right函数分解字符串
建立一个循环就可以赋值了

解决方案 »

  1.   

    Open "c;\123.txt" For Input As #1
        Do Until EOF(1)
            Line Input #1, strNextLine
            '在这里按","分段取值
        Loop
        Close #1
      

  2.   

    这个小函数可以分段取值:'to get the index value of the a string devided by ","
    'for example extract("ab,c,de",",",0) will get a value of "ab"
    Public Function Extract(Text As String, strSeparator As String, ByVal Index As Long) As String
        Dim strColl As New VBA.Collection
        Dim lngStart As Long 'the first place finding begin
        Dim lngLoc As Long 'the position of ","
        Dim lngLocPrev As Long
        Dim blnEnd As Boolean
        
        blnEnd = False
        lngStart = 1
        lngLocPrev = 0
        
        Do While Not blnEnd
          lngLoc = VBA.InStr(lngStart, Text, strSeparator)
          If lngLoc <> 0 Then
            If (lngLoc <> lngStart) Then
               strColl.Add VBA.Mid(Text, lngStart, lngLoc - lngStart)
            End If
            lngStart = lngLoc + VBA.Len(VBA.Trim(strSeparator))
           Else
            strColl.Add VBA.Mid(Text, lngStart)
            blnEnd = True
          End If
        Loop
          
        If (0 <= Index) And (Index < strColl.count) Then
          Extract = VBA.Trim(strColl.Item(Index + 1))
         Else
          Extract = ""
        End If
        Set strColl = Nothing
    End Function
      

  3.   

    比如
    str = 1,2.0,3,254,786.258,89
    36.9,89.012,86,0,5
    3.698
    5.789,86.3str = str & ","
    dim i as integer, j as integer, k as integer
    k = 0
    for i = 1 to strlen
      j = instr(1,str,",", vbTextCompare)
      if j <> 0 then
        text1(k) = mid(str,1,j-1)
        str = right(str,len(str) - j)  '将字符串截短
        k = k+1
      else
        exit for
      end if
    next