Excel VBATutorial          


Excel VBA Macros

Email to excel-vba.com

Excel Tutorial on Macros

 Excel Consulting

Here is a sample of what you will find
in the downloadable 
Tutorial on Excel macros

VBA Code for Workbooks

To develop a VBA procedure that is triggered by an event relating to the workbook (when you open it, when you save it, when you close it) see the VBA lesson on events.


ThisWorkbook is the workbook within which your VBA procedure runs. So if you write:
The workbook within which your VBA procedure (macro) runs will be saved.

If you want to close the workbook within which your VBA procedure (macro) runs without saving it you will write these two lines of code:

Verifying the existence of a file

When you want to verify if a certain file exists on your disk you will use the following code that means "If the file "C:\Stuff\toto.xls" does not exist then":
If Dir("C:\Stuff\toto.xls") = "" Then

You could also use a sentence that means "If the file "C:\Stuff\toto.xls" does exist then":
If Dir("C:\Stuff\toto.xls") <> "" Then

If you are looking in the same folder as the file in which the macro runs you can simplify the VBA code:
If Dir("toto.xls") <> "" Then

In the downloadable tutorial on Excel macros you will find many other uses for Dir including opening all the files of a folder to generate a consolidated database (whatever the number of files in the folder). You will also learn about Path, ActiveWorkbook, Windows, Kill, and many other VBA words to work with one or many workbooks.

We hope you have enjoyed this tip
For more on this topic and a complete course on Excel macros download the
Tutorial on Excel Macros

To organize your discovery of Excel macros, the downloadable Tutorial on Excel Macros is divided in three sections (all 3  sections part of the single download):

Section 1: Excel Macros Programming (Chapters 1 to 10)
This section is about recording, writing, modifying and testing macros in the Visual Basic Editor. You will also learn about security and discover "events" (an event is what starts the macro).

Section 2: Excel VBA Vocabulary (Chapters 11 to 23)
Developing a macro is communicating with Excel and to do so you need to use a language called Visual Basic for Applications (VBA). In section 2 you will learn all the VBA vocabulary that is essential to work with business data (accounting, sales, production and others).

Section 3: Forms and Controls in VBA for Exce (Chapters 24 to 33)
The userform is a small or large dialog window that you create and allows the user to submit values that will be used by your macros. To these userforms you will add controls (command buttons, text boxes, list boxes and others) and program them.