Sub Macro() 'la macro dont on veut étudier les variables
Dim MaVar1, MaVar2, MaVar3, MaVar4 'déclarations obligatoirement sur 1 ligne
MaVar1 = F1(1, 1)
MaVar2 = F1(1, 0)
MaVar3 = F2(1, 2, 3)
MaVar4 = MaVar1 + MaVar2
End Sub
Function F1(v1, v2)
F1 = IIf(v1 = 1 And v2 = 1, 1, 0)
End Function
Function F2(x1, x2, x3)
F2 = [1/0]
End Function
Sub Resultat()
Dim i, n, j, x, p, k, s, kk
Open ThisWorkbook.Path & "\Resultat.txt" For Output As #1
Print #1, "[Variables]"
With ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
For i = 1 To .CountOfLines
If .Lines(i, 1) Like "Sub Macro()*" Then Exit For 'macro recherchée
Next i
If i > .CountOfLines Then Exit Sub 'si la macro n'existe pas
n = UBound(Split(.Lines(i + 1, 1), ",")) + 1
Print #1, "NbVar=" & n
For j = i + 2 To i + n + 1
x = .Lines(j, 1)
Print #1, "NomVar" & j - i - 1 & "=" & Left(x, InStr(x, " = ") - 1)
Next j
For j = i + 2 To i + n + 1
Print #1, ""
x = .Lines(j, 1)
Print #1, "[" & Left(x, InStr(x, " = ") - 1) & "]"
x = Mid(x, InStr(x, " = ") + 3)
p = InStr(x, "(")
If p Then
x = Left(x, p - 1)
Print #1, "TypeVar=" & x 'fonction
For k = 1 To .CountOfLines
If .Lines(k, 1) Like "Function " & x & "(*" Then
x = Replace(Split(.Lines(k, 1), "(")(1), ")", "") 'liste des arguments de la fonction
s = Split(x, ", ")
For kk = 0 To UBound(s)
Print #1, "Param" & kk + 1 & "=" & s(kk)
Next kk
Exit For
End If
Next k
Else
Print #1, "TypeVar=" & x 'formule
End If
Next j
End With
Close #1
End Sub