Error 14, “Out of string space”, is the string-specific sibling of out of memory. VBA keeps strings in a managed pool, and this error fires when string data grows past what that pool can hold, most often one giant string assembled piece by piece, or an array of strings with no upper bound on its growth. The code is asking for more text storage than the design allows.
s = s & piece copies the whole accumulated text. At scale this is both slow and space-hungry; it is the number one cause of error 14.Dim parts() As String, i As Long
ReDim parts(1 To rowCount)
For i = 1 To rowCount
parts(i) = BuildLine(i)
Next i
result = Join(parts, vbCrLf) ' one allocation at the end
If the volume is modest and error 14 still fires, look for accidental exponential growth: a string variable accidentally concatenated to itself, or a replace loop whose replacement contains the search text, so each pass makes the string longer. Print the length at intervals; doubling lengths expose it immediately.
What is the difference between error 7 and error 14? Error 7 is a general allocation failure; error 14 is specifically about string storage. In practice both point at unbounded growth, and both are usually fixed by restructuring how the code accumulates data.
Can a single string really be too big? Yes. A string approaching the process memory limit, built by repeated concatenation, can trigger error 14 on its own, especially in a 32-bit host application.