Introduction
VBAFuncRecord is a binary structure used to represent a single method within a VBA module. It describes various aspects of the function or sub, such as its name, visibility, return type, and argument list.
Structure Description
| Information name |
Offsets |
Value Type |
| Flag1 |
0 |
byte |
| Flag2 |
1 |
byte |
| RecordName |
2 |
string |
| NextRecord |
4 |
int32 |
| UserMemId |
8 |
int32 |
| HelpID |
12 |
int32 |
| DescOffset |
16 |
int32 |
| InvokeFuncOffset |
20 |
int16 |
| HasUserMemFlag |
25 |
byte |
Version-dependent fields
These field are present for all version, but with different position.
A and B represent version-dependent offset for these fields, with following values:
| VBA Version |
A |
B |
| 5 or below (x86) |
0 |
0 |
| 6 or higher (x86) |
4 |
0 |
| 6 or higher (x64) |
20 |
6 |
| Information name |
Offsets |
Value Type |
| ArgsOffset |
36 + A |
int32 |
| RetType |
40 + A |
uint32 |
| DeclOffset |
44 + A |
uint16 |
| Unk46 |
46 + A |
uint16 |
| Unk48 |
48 + A |
uint16 |
| Unk50 |
50 + A |
uint16 |
| Unk52 |
52 + A |
uint16 |
| Information name |
Offsets |
Value Type |
| SpecialFlag |
54 + A + B |
byte |
| ArgCount |
55 + A + B |
byte |
| HasParamArray |
56 + A + B |
byte |
| NewProcFlags |
57 + A + B |
byte |
| Unk58 |
58 + A + B |
byte |
Flag1 bits
| Information name |
Bit Position |
Value Type |
| IsPrivate |
Flag1 bit 0 |
bool |
| HasShorthandType |
Flag1 bit 4 |
bool |
| HasExplicitType |
Flag1 bit 5 |
bool |
| IsStatic |
Flag1 bit 7 |
bool |
Flag2 bits
The Flag2 field is a byte that contains flags related to the type of method being parsed.
| Information name |
Bit Position |
Value Type |
| IsFunction |
Flag2 bit 4 |
bool |
| IsPropertyGet |
Flag2 bit 5 |
bool |
| HasNew |
Flag2 bit 5 |
bool |
| IsPropertyLet |
Flag2 bit 6 |
bool |
| IsPropertySet |
Flag2 bit 7 |
bool |
HasUserMemFlag bits
| Information name |
Bit Position |
Value Type |
| HasUserMemId |
HasUserMemFlag bit 5 |
bool |
The HasUserMemId indicates whether the UserMemId field for a given function or sub has been set.
In VBA, a developer can add a unique identifier to a function or sub using the Attribute statement, like this:
Attribute MyID.VB_UserMemId = 1
More details about UserMemId here.
SpecialFlag bits
| Information Name |
Bit Position |
Value Type |
| HasReturnValue |
Bit 5 |
bool |
| HasDeclare |
Bit 7-6 |
bool |
The SpecialFlag variable is a single byte where each bit indicates whether the function or sub has certain attributes.
- Bit 5 (counting from the least significant bit) is used to indicate whether the function or sub has a return value.
- Bit 7-6 are used to indicate whether the function or sub is an API declaration statement.
NewProcFlags bits
| Information Name |
Bit Position |
Value Type |
| IsPrivate |
Bit 1 |
bool |
| IsFriend |
Bit 2 |
bool |
| IsPtrSafe |
Bit 6 |
bool |
The NewProcFlags variable is a single byte where each bit indicates whether the function or sub has certain attributes.
- Bit 1 is used to indicate whether the function or sub is private.
- Bit 2 is used to indicate whether the function or sub is a friend function (VBA term for a function that is accessible from other modules within the same project).
- Bit 6 is used to indicate whether the function or sub has been marked as “PtrSafe”, which is a feature introduced in VBA 7.0 to help ensure that calls to external libraries are safe in a 64-bit environment.