Search notes:

VBA function: mid

mid(text, start, len) extracts the portion from the string text that starts at character start and has len characters.
Thus, mid() is the equivalent of the function which is called substr, substring or similar in other programming languages.
start must be greater than zero. mid(text, 0, n) causes a runtime error 5 (Invalid procedure call or argument).
dim result as string
result = mid("The foo bar", 5, 3) ' Assign "foo" to result.

Assigning a value to the result of mid

The result of mid is an l-value and thus can be assigned, albeit in a limited fashion: only a text of the length of the replaced text is replaced:
option explicit

sub main() ' {

    dim txt as string

    txt = "one xxx three"
    mid(txt, 5, 3) = "two"
    debug.print txt           ' one two three

    txt = "ONE XY THREE"
    mid(txt, 5, 2) = "TWO"
    debug.print txt           ' ONE TW THREE

end sub ' }
Github repository about-VBA, path: /functions/mid/assign.vb

See also

VBA functions

Index