Visual Basic for Applications is the programming language of Microsoft Office applications. VBA to automate tasks, create complete applications, secure your entries and documents, create new menus and new features to boost your software effectively.
VBA uses the same language as Microsoft Visual Basic. The difference between VBA and VB is that VB is a complete package that allows you to develop applications independently and freely distributable, so that an application made in VBA is completely linked to the software in which it was created (an application created in Excel VBA does cannot embark on a post if Excel is not installed).
Before that Excel uses this programming language, the software used its own programming language and an application was called macro. This term has remained, but a macro in VBA Excel produced nothing but a procedure such that they are carried out under VB. A programmer in VBA has no problem to switch to VB and vice-versa.
VBA is accessible to all. However, a good knowledge of Excel is necessary before embarking on the creation of application. Indeed, it is important to master the main VBA manipulates objects as objects Workbook (workbook) Worskheet (Spreadsheet), Range (cell range), etc. This should not be a hindrance for those who want to start because words can quickly familiar, are needed. VBA, powerful language, flexible and easy to use all.
VBA Macro Recorder :
Excel, Word, PowerPoint has a great tool: the macro recorder. It creates a macro in VBA and transforms all orders placed by the user in the host application. It automates without any knowledge of programming some of your tasks and also to become familiar with VBA.
How To Use
Here is an example to use this tool. For that here is the example. I want to put in the same format all the tables that I create. Rather than reproduce the same commands every time, I'll use the macro recorder.
- I select my first table. Indeed, if I select it after launching the recording, the macro selection at each recurrence of this launch and still runs on the same cells.
- Start the recording via the menu "Tools - Macro - Record New Macro.
- Macro name: It is important to explicitly rename the macro. The macro name must begin with a letter and must not contain spaces. Use the underscore to separate words.
- Shortcut key: It is possible to create a keyboard shortcut to start the macro by typing a letter. You can use uppercase and run the macro by the Ctrl + Shift + letter.
- Save the macro: workbook containing the macro. The macro will then run if the workbook where the macro was recorded is open. If you choose "Personal Macro Workbook", a new workbook is created and saved in the folder so that your macros are available whenever you use Excel.
- Description: You can give a description to your macro.
- After clicking OK, the macro will record all the commands that I use. Here, I change the format of my table (Color, Font, Frame).
- Then I stop the recording by clicking on the button Stop Recording or Tools-Macro Stop Recording. The macro is created.
- I have a new table that I want to replicate the same format:
- I select my new table and I'll use the macro you created earlier (if the workbook in which it was registered to be opened). I start by selecting Tools-Macro-Macros"
- I select the macro you want, then I click Run
- I could have run the macro the keyboard shortcut Ctrl + f "I had set at its inception.
Some precautions to take when using it:
- Well-think of the commands that you want to register to avoid creating unnecessary code.
- Know-how in the macro workbook save for future use.
- Rename macros explicitly.
Limitations of the Macro Recorder:
- It can only translate the orders placed by the user in the host application and usually writes more lines of code needed. When writing macros, we will see how to use and reduce the code created by the recorder. Macros created are visible and editable via the macro editor VBE (Visual Basic Editor).
Bookmarks