Procedure declaration may not be inside a control block
You tried to include a Function, Property Get, Property Set, or Sub statement inside one or another of the following block statements: Do , For, ForAll, If...Then...Else...EndIf, Select, While. This is not allowed. For example:
If 1 = 1 Then
Sub MySub ' Illegal
' ...
End Sub
End If
Move the Function, Property Get, Property Set, or Sub statement to outside the block.