Recherche…


Remarques

Blocs de commentaires

Si vous avez besoin de commenter ou de commenter plusieurs lignes à la fois, vous pouvez utiliser les boutons d' édition de la barre d'outils de l'EDI:

Bloc de commentaire - Ajoute une seule apostrophe au début de toutes les lignes sélectionnées

Bloc de commentaires

Uncomment Block - Supprime la première apostrophe du début de toutes les lignes sélectionnées

Décommenter le bloc

Commentaires multilignes De nombreux autres langages prennent en charge les commentaires de bloc multi-lignes, mais VBA n'autorise que les commentaires sur une seule ligne.

Commentaires Apostrophe

Un commentaire est marqué par une apostrophe ( ' ) et ignoré lorsque le code est exécuté. Les commentaires aident à expliquer votre code aux futurs lecteurs, y compris vous-même.

Comme toutes les lignes commençant par un commentaire sont ignorées, elles peuvent également être utilisées pour empêcher l'exécution du code (pendant le débogage ou le refactorisation). Placer une apostrophe ' avant votre code en fait un commentaire. (Ceci s'appelle commenter la ligne.)

Sub InlineDocumentation()
  'Comments start with an "'"

  'They can be place before a line of code, which prevents the line from executing
  'Debug.Print "Hello World"

  'They can also be placed after a statement
  'The statement still executes, until the compiler arrives at the comment
  Debug.Print "Hello World"  'Prints a welcome message

'Comments can have 0 indention....
     '... or as much as needed

  '''' Comments can contain multiple apostrophes ''''

  'Comments can span lines (using line continuations) _
    but this can make for hard to read code

  'If you need to have mult-line comments, it is often easier to 
  'use an apostrophe on each line

  'The continued statement syntax (:) is treated as part of the comment, so 
  'it is not possible to place an executable statement after a comment
  'This won't run : Debug.Print "Hello World"
End Sub

'Comments can appear inside or outside a procedure

Commentaires de REM

Sub RemComments()
  Rem Comments start with "Rem" (VBA will change any alternate casing to "Rem")
  Rem is an abbreviation of Remark, and similar to DOS syntax
  Rem Is a legacy approach to adding comments, and apostrophes should be preferred

  Rem Comments CANNOT appear after a statement, use the apostrophe syntax instead
  Rem Unless they are preceded by the instruction separator token
  Debug.Print "Hello World": Rem prints a welcome message
  Debug.Print "Hello World" 'Prints a welcome message

  'Rem cannot be immediately followed by the following characters "!,@,#,$,%,&"
  'Whereas the apostrophe syntax can be followed by any printable character.

End Sub

Rem Comments can appear inside or outside a procedure


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow