Description
Represents a Visual Basic module in a workbook.
Accessors
The Module object is a member of the Modules collection. The Modules collection contains all the Module objects in a workbook. Use the Add method to create a new module and add it to the collection. To access a single member of the collection, use the Modules method with the index number or name of the module as an argument.
The module index number represents the position of the module on the tab bar of the workbook. Modules(1) is the first (leftmost) module in the workbook; Modules(Modules.Count) is the last. All modules are included in the index count, even if they are hidden.
The following example hides module two in the active workbook.
Modules(2).Visible = False
The module name is shown on the workbook tab for the module. Use the Name property to set or return the module name (you cannot change the name of the module where the Visual Basic code is running, however). The following example protects the Visual Basic code on the module named "Sample Code."
Modules("sample code").Protect password:="drowssap", contents:=True
The Module object is also a member of the Sheets collection. The Sheets collection contains all of the sheets in the workbook (chart sheets, dialog sheets, modules, and worksheets). To access a single member of the collection, use the Sheets method with the index number or name of the sheet as an argument.
When a module is the active sheet, you can use the ActiveSheet property to refer to it. The following example uses the Activate method to activate the module named "Module1" and then protects the module.
Modules("module1").Activate ActiveSheet.Protect
Properties
Application Property, Creator Property, Index Property, Name Property, Next Property, OnDoubleClick Property, OnSheetActivate Property, OnSheetDeactivate Property, PageSetup Property, Parent Property, Previous Property, ProtectContents Property, Visible Property.
Methods
Activate Method, Copy Method, Delete Method, InsertFile Method, Move Method, PrintOut Method, Protect Method, SaveAs Method, Select Method, Unprotect Method.