Tutorial by Examples

To print a listing of the Error Code descriptions to the Immediate Window, pass it to the Debug.Print function: Private Sub ListErrCodes() Debug.Print "List Error Code Descriptions" For i = 0 To 65535 e = Error(i) If e <> "Application-defined or obje...
The Stop command will pause the execution when called. From there, the process can be resumed or be executed step by step. Sub Test() Dim TestVar as String TestVar = "Hello World" Stop 'Sub will be executed to this point and then wait for the user Ms...
If you would like to test a line of macro code without needing to run an entire sub, you can type commands directly into the Immediate Window and hit ENTER to run the line. For testing the output of a line, you can precede it with a question mark ? to print directly to the Immediate Window. Altern...
The first step in optimizing for speed is finding the slowest sections of code. The Timer VBA function returns the number of seconds elapsed since midnight with a precision of 1/256th of a second (3.90625 milliseconds) on Windows based PCs. The VBA functions Now and Time are only accurate to a secon...
You can easily add a breakpoint to your code by clicking on the grey column to the left of the line of your VBA code where you want execution to stop. A red dot appears in the column and the breakpoint code is also highlighted in red. You can add multiple breakpoints throughout your code and resumi...
The Locals window provides easy access to the current value of variables and objects within the scope of the function or subroutine you are running. It is an essential tool to debugging your code and stepping through changes in order to find issues. It also allows you to explore properties you might...

Page 1 of 1