- VBA Automation for Excel 2019 Cookbook
- Mike Van Niekerk
- 289字
- 2021-06-11 18:16:31
Creating a module for storing a Sub procedure
In this recipe, we will be creating a new module, which is yet another object, in the Project window. So far, we've seen only two objects in the Project window: Sheet1 and ThisWorkbook. It is possible to create a code window for each, but Sub procedures must be created and stored in a module in the Project window. This is where coding for all objects can be created and saved.
Getting ready
Make sure that Excel is open and that the VBA Editor is visible.
How to do it…
The steps for this recipe are as follows:
- With Excel open on a new sheet, select the Developer tab. In the Code group, select the Visual Basic icon to activate the VBA Editor. If you prefer using the shortcut key, simply press Alt + F11.
In the VBA Editor, observe the Project window. Under Microsoft Excel Objects, only two objects are visible: Sheet1 (Sheet1) and ThisWorkbook.
- On the menu bar, select Insert. From the drop-down menu, select Module, as shown:

Figure 2.14 – The Insert menu's Module option
Once you've made your selection, the VBA Editor adds a new module – visible in the Project window – and a new code window appears on the right:

Figure 2.15 – Newly inserted module
How it works…
When you open a new spreadsheet in Excel and then activate the VBA Editor, no modules will be visible in the Project window.
However, should you record a macro and then activate the VBA Editor, that macro will be stored in a module.
Finally, if you choose not to record a macro, but to insert the code yourself, you have to create a module yourself.
- 數(shù)據(jù)科學實戰(zhàn)手冊(R+Python)
- 計算思維與算法入門
- 流量的秘密:Google Analytics網(wǎng)站分析與優(yōu)化技巧(第2版)
- JavaScript:Functional Programming for JavaScript Developers
- 零基礎學Scratch少兒編程:小學課本中的Scratch創(chuàng)意編程
- Access 2010數(shù)據(jù)庫基礎與應用項目式教程(第3版)
- 編譯系統(tǒng)透視:圖解編譯原理
- Mastering Rust
- Instant RubyMotion App Development
- VMware虛擬化技術
- iOS開發(fā)實戰(zhàn):從入門到上架App Store(第2版) (移動開發(fā)叢書)
- C語言程序設計上機指導與習題解答(第2版)
- OpenCV 3 Blueprints
- HTML5游戲開發(fā)實戰(zhàn)
- Test-Driven iOS Development with Swift