Runtime Error 458: “Variable uses a type not supported in Visual Basic,” explained and fixed
Error 458, “Variable uses a type not supported in Visual Basic”, fires when a value arrives in a data type VBA has no equivalent for. VBA's type system is deliberately small; Automation and API layers are not. A method in an external library returning an unsigned type VBA lacks, a Variant carrying an exotic subtype, or a structure field typed beyond Basic's set will raise 458 when VBA is asked to hold the value. The data is fine in its home system; it simply does not fit in a VBA variable.
For people who just run the program
- This is an integration-level error. It appears where macros receive values from other programs or libraries whose data types exceed what VBA can store; documents and settings are not involved.
- Note the feature and the source system. Which external program or library supplied the value is the essential fact.
- Version alignment matters. A library update that starts returning a newer type can introduce 458 to code that worked for years; report recent upgrades of the connected system.
- Report the number to the maintainer. The remedy is a conversion layer in the code, which only the code's owner can add.
For people who write the code
- Convert at the boundary. Ask the library for a representation VBA can hold (most offer string or double forms of exotic numerics), or receive into a byte array and assemble the value manually. Do not let an unsupported subtype travel deeper into the program than the call that produced it.
- Know the notorious subtypes. Unsigned 64-bit integers, certain decimal and currency variants from other languages, and by-reference arrays of unusual element types are repeat offenders. A Variant's
VarType at the failure point identifies the subtype you are actually holding.
Dim v As Variant
v = api.GetReading()
Debug.Print VarType(v) ' identify the unsupported subtype first
' then convert with the library's own ToString/ToDouble equivalent
- Declare API structures with VBA-safe substitutes. In Declare-based structures, fields whose C types have no VBA twin (unsigned types, long double) must be modeled as byte blocks or split fields and marshaled by hand; declaring them as the nearest VBA type invites 458 (or silent corruption).
Error 458 is not a corruption warning. Nothing is damaged; the value is unrepresentable. Retrying the same call returns the same type and the same error, so the fix is conversion, not persistence.
If it still happens
If the type is nominally supported and 458 persists, the value may be an array of the type rather than the type itself, or wrapped in a Variant array whose element type is the unsupported one. Inspect VarType's array bits and handle the conversion element by element.
Common questions
Which types does VBA not support? VBA has no unsigned integers beyond Byte, no 64-bit floating types beyond Double, and no equivalents for several COM Automation subtypes other languages produce. Values in those forms must be converted before VBA can hold them.
Can error 458 come from my own code alone? Rarely. Pure VBA code can only create values in VBA types. Error 458 almost always involves an external source: an Automation library, an API call, or data read from a foreign format.
Related errors