Public Function validateCNPJ(cnpj As String) As Boolean
Dim digits(13) As Variant
Dim stCalc As Variant: stCalc = Array(6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9)
Dim ndCalc As Variant: ndCalc = Array(5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9)
Dim stRes As Long
Dim ndRes As Long
If Len(cnpj) < 14 Then
cnpj = String(14 - Len(cnpj), "0") & cnpj
End If
For i = LBound(digits) To UBound(digits)
digits(i) = Mid(cnpj, i + 1, 1)
Next
For i = LBound(stCalc) To UBound(stCalc)
stRes = stRes + (digits(i) * stCalc(i))
ndRes = ndRes + (digits(i) * ndCalc(i))
Next
stRes = stRes Mod 11
If stRes = 10 Then stRes = 0
ndRes = ndRes + (stRes * ndCalc(LBound(ndCalc)))
ndRes = ndRes Mod 11
If ndRes = 10 Then ndRes = 0
If digits(12) = stRes And digits(13) = ndRes Then validateCNPJ = True Else validateCNPJ = False
End Function