美文网首页
简明Excel VBA(十二) VBA Best Practic

简明Excel VBA(十二) VBA Best Practic

作者: Bluetata | 来源:发表于2018-12-08 21:58 被阅读0次

    简明Excel VBA

    本文集同步于GitHub仓库:# Youchien/concise-excel-vba

    0x06 VBA Best Practices

    1. Always have Option Explicit at the top of your code modules to
      enforce variable declaration.
    2. Never write procedures and functions that are longer than a full screen
      as these are hard to understand. Procedures should fit on one screen -
      ie be 40-50 lines long maximum.- ie be 40-50 lines long maximum.
    3. Always prefix your variables so you can quickly identify their datatype.
    4. Never use the Variant datatype unless absolutely necessary.</br>
      :尽量不要使用Variant,要显示的声明具体的数据类型。Variant是VBA中的一种特殊类型,
      所有没有声明的数据类型的变量都默认是Variant型。但Variant型所占的存储空间远大于其他的
      数据类型,所以除非必要,否则应该避免申明变量为Variant型。
    5. Always use the keyword "Call" to call your procedures.
    6. Always put your arguments in parentheses.
    7. Never use Global variables unless absolutely necessary.
      Pass parameters ByVal (ByRef is the default) - only use ByRef where
      you intend to modify the parameter and pass the change back to the caller.
    8. Always use tabs to indent your code to bring structure, never use spaces.
    9. Add "value added" comments which explain why, do not add trivial comments.
    10. Always add an Error Handler to every procedure and function.
    11. Use the line continuation character to make your code more readable and
      to reduce the amount of scrolling.
    12. Never use the Option Base or Option Compare statements.

    相关文章

      网友评论

          本文标题:简明Excel VBA(十二) VBA Best Practic

          本文链接:https://www.haomeiwen.com/subject/shuchqtx.html