Wednesday, September 14, 2022

How to insert and start writing VBA code.

Before started module must be insert as below.

  • Open Visual Basic Editor(VBE) by pressing Alt + F11 or read here for more detail.
  • Click insert Tab follow by module.

  • Default inserted Module name Module1..2..3 and etc.
    (Module can be rename later by accessing their property)


    My default setting every module inserted with Option Explicit declaration will explain later.

There are 2 ways to start writing VBA code.

  • Direct type in Sub>Space>Macro Name>Open Bracket>Close Bracket and hit enter
    Ex. Sub My1StVBACode() and hit enter automatically End Sub appeared as below.


    Now we can start writing any code or copy code given and paste here.
    OR
  • Click insert Tab follow by Procedure.

  • Key in My1StVBACode inside Name Box and click OK.


    Let default setting for the rest and will be explain later.
  • The procedure appeared as below.

Note:

  1. Sub is equal to Public Sub and can be called from anywhere.
  2. This is Called procedure and listed under macro name when run macro.

Microsoft Reference - Sub Statement

Practice makes perfect. Thank You.

No comments:

Post a Comment