Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Option Explicit catch ReDim <undeclared>?

Does anyone know why this doesn't throw a Variable not defined error when I compile it?

'Class1.cls'
Option Explicit

Public Sub foo()
    ReDim fubar(1 To 2, 1 To 1)
End Sub

Am I misunderstanding how Option Explicit is supposed to work? Or is there something wrong with this test? Or is this just a bug in VBA?

(I am testing this on Excel 2007)

like image 330
RBarryYoung Avatar asked May 10 '13 16:05

RBarryYoung


1 Answers

From MSDN (http://msdn.microsoft.com/en-gb/library/y9341s4f%28v=vs.80%29.aspx)

"When Option Explicit appears in a file, you must explicitly declare all variables using the Dim or ReDim statements."

So ReDim works in Option Explicit.

like image 88
Adrien Lacroix Avatar answered Nov 11 '22 20:11

Adrien Lacroix