2007/06/17

VBA getConfig: retreive key:value from a config sheet


    Function getConfig(key As String) As String
    Dim i As Integer
    Dim xKey As String, strFila As String
    Dim sh

    Set sh = Sheets("config")

    For i = 1 To 500
    strFila = Trim(Str$(i))
    xKey = sh.Range("A" + strFila).Value

    If (key = xKey) Then
    getConfig = sh.Range("B" & strFila).Value
    Exit Function
    End If

    If (xKey = "[end]") Then Exit For

    Next i

    MsgBox "ERROR key not found in config page: [" & key & "]", _
    vbOKOnly + vbCritical, "ERROR"

    End
    End Function

No comments: