Home Products Tips VBA OfficeOne on Windows Links

Split Strings

Unlike Microsoft PowerPoint 2000, Microsoft PowerPoint 2004 does not include a Split() function in VBA. The Split() function is useful for splitting a string into components that are delimited. The following VBA code can be used for splitting strings:

Sub SplitStrings(ByVal Str As String, _
    ByVal Delimiter As String, _
    ByRef C As Collection)

    Dim S As String
    Dim L As Long
    Dim K As Long

    L = 1
    K = InStr(L, Str, Delimiter)
    Do While K > 0
        S = Mid(Str, L, K - L)
        C.Add S
        L = K + Len(Delimiter)
        K = InStr(L, Str, Delimiter)
    Loop
    S = Mid(Str, L, Len(Str))
    C.Add S
End Sub

Sub Test()
    Dim C As New Collection
    Dim S As String
    Dim I As Long

    SplitStrings "1::2::3::4", "::", C
    For I = 1 To C.Count
        S = S + C(I) + vbCr
    Next
    MsgBox S
End Sub


Home | Products | Tips | VBA | Windows | Links

Contact OfficeOne on email at officeone@officeonemac.com. Copyright © 2001-2013 OfficeOne. All rights reserved.

page counter