VBA - Len

La fonction Len renvoie la longueur de la chaîne d'entrée donnée, y compris les espaces vides.

Syntaxe

Len(String)

Exemple

Ajoutez un bouton et ajoutez la fonction suivante.

Private Sub Constant_demo_Click()
   Dim var1 as Variant
   Dim var2 as Variant
   
   var1 ="Microsoft VBScript"
   msgbox("Length of var1 is : " & Len(var1))
  
   var2 =       "       Microsoft VBScript           "
   msgbox ("Length of var2 is : " & Len(var2))
End Sub

Lorsque vous exécutez la fonction ci-dessus, elle produit la sortie suivante.

Length of var1 is : 18
Length of var2 is : 36