I have an Excel VBA module that uses Hashtable and SortedList from the .NET 3.5 mscorlib DLL. I'm able to use these classes with no issues. When I attempted to use the StringBuilder class, I ran into an automation error. Here's the entire function that is in an Excel VBA module:
Function StringBuilderTest() As String
Dim sb As StringBuilder
Dim i as Integer
On Error GoTo ErrorLabel
Set sb = New StringBuilder
For i = 1 to 100
sb.Append "text"
Next i
StringBuilderTest = sb.ToString
Exit Function
ErrorLabel:
Debug.Print Err.Description
Debug.Print Err.Number
Debug.Print Err.Source
StringBuilderTest = "Error"
Exit Function
End Function
The code blows up on the .Append method call. Error handling outputs the following:
Class does not support Automation or does not support expected interface
430
VBAProject
Here are my Excel reference settings:
And here are my Windows Features settings:
Why am I getting this error? It's a mystery, given Hashtable and SortedList from the same library work fine.
UPDATED:
I added a For/Next loop around the Append method call to more accurately represent my intent. Note that this is simplified code (not actually from my Excel project), to illustrate the Automation issue I'm having.


The issue you're encountering I think is because the StringBuilder class from the .NET Framework is not directly accessible in VBA. VBA doesn't have native support for using .NET classes.
However, there are alternative approaches you can use :