Pages

Tuesday, February 17, 2015

Must know VBA Statements for Excel VBA Programming

Below is the list of VBA statement and the details about what action it executes.

1. Option Explicit - Forces declaration of all variables in a module

2. Option Private - Indicates that an entire module is Private

3. Private                 - Declares a local array or variable

4. Public                  - Declares a public array or variable

5. Dim                 - Declares variables and (optionally) their data types

6. AppActivate - Activates an application window

7. Beep                 - Sounds a tone via the computer's speaker

8. Close                 - Closes a text file

9. Const                 - Declares a constant value

10. Call                 - Calls another macro, write name of the other macro in front of Call

11. ChDir         - Changes the current directory

12. MkDir         - Creates a new directory

13. ChDrive         - Changes the current drive

14. Date                 - Sets the current system date

15. Declare         - Declares a reference to an external procedure in a Dynamic Link Library (DLL)

16. DeleteSetting - Deletes a section or key setting from an application's entry in the Windows Registry

17. Do-Loop          - Loops through a set of instructions

18. Exit Do          - Exits a block of Do-Loop code

19. For-Next          - Loops through a set of instructions a specific number of times

20. For Each-Next    - Loops through a set of instructions for each member of a collection

21. Exit For          - Exits a block of For-Next code

22. Function           - Declares the name and arguments for a Function procedure

23. Exit Function   - Exits a Function procedure

24. Property Get   - Declares the name and arguments of a Property Get procedure

25. Property Let   - Declares the name and arguments of a Property Let procedure

26. Property Set         - Declares the name and arguments of a Property Set procedure

27. Exit Property        - Exits a property procedure

28. Exit Sub               - Exits a subroutine procedure

29. End                    - Used by itself, exits the program; also used to end a block of statements that begin with If, With, Sub, Function, Property, Type, or Select

30. Name                   - Renames a file or directory

31. On Error            - Gives specific instructions for what to do in the case of an error

32. On...GoSub    - Branches, based on a condition

33. On...GoTo            - Branches, based on a condition

34. Open                    - Opens a text file

35. Option Base    - Changes the default lower limit for arrays

36. Option Compare   - Declares the default comparison mode when comparing strings

37. Erase                     - Re-initializes an array

38. Error                      - Simulates a specific error condition

39. FileCopy              - Copies a file

40. Let                      - Assigns the value of an expression to a variable or property

41. Line Input #      - Reads a line of data from a sequential text file

42. Load                       - Loads an object but doesn't show it

43. Lock...Unlock       - Controls access to a text file

44. Mid                       - Replaces characters in a string with other characters

45. Print #               - Writes data to a sequential file

46. Get                       - Reads data from a text file

47. GoSub...Return       - Branches to and returns from a procedure

48. GoTo                       - Branches to a specified statement within a procedure

49. If-Then-Else        - Processes statements conditionally (the Else part is optional)

50. Input #                - Reads data from a sequential text file

51. Kill                        - Deletes a file

52. Stop                          - Pauses the program

53. Sub                           - Declares the name and arguments of a Sub procedure

54. Time                         - Sets the system time

55. Type                         - Defines a custom data type

56. Unload                      - Removes an object from memory

57. While...Wend           - Loops through a set of instructions as long as a certain condition remains true

58. Width #                    - Sets the output line width of a text file

59. With                        - Allows a shorthand way of accessing multiple properties for an object

60. Write #                - Writes data to a sequential text file

61. Put                        - Writes a variable to a text file

62. RaiseEvent        - Fires a user-defined event

63. Randomize        - Initializes the random number generator

64. ReDim                - Changes the dimensions of an array

65. Rem                        - Specifies a line of comments (same as an apostrophe ['])

66. Reset                        - Closes all open text files

67. Resume                - Resumes execution when an error-handling routine finishes

68. RmDir                - Removes an empty directory

69. SaveSetting        - Saves or creates an application entry in the Windows Registry

70. Seek                        - Sets the position for the next access in a text file

71. Select Case        - Processes statements conditionally

72. SendKeys                - Sends keystrokes to the active window

73. Set                        - Assigns an object reference to a variable or property

74. SetAttr                - Changes attribute information for a file

75. Static                        - Declares variables at the procedure level so that the variables retain their values as long as the code is running and the project hasn't been reset.

No comments:

Post a Comment