Skip to content

VBA007 — ByRef argument type mismatch

Severity: 🔴 error Category: signature Phase: 0

Description

A ByRef parameter receives a variable whose type does not match the parameter type.

Failing example

Sub Inc(ByRef n As Long): n = n + 1: End Sub
Dim s As String: Inc s

Compliant example

Sub Inc(ByRef n As Long): n = n + 1: End Sub
Dim n As Long: Inc n

How to fix

Use a temporary variable of the matching type, or change the parameter to ByVal if a copy is acceptable.


Source: src/rules.py — entry VBA007.