Como?
Bem, use o código abaixo e divirta-se!
CreateNewModule ActiveWorkbook, 1, "TestModule"Sub CreateNewModule (ByVal wb As Workbook, _ByVal ModuleTypeIndex As Integer, _ByVal NewModuleName As String)' creates a new module of ModuleTypeIndex' (1=standard module, 2=userform, 3=class module) in wb' renames the new module to NewModuleName (if possible)Dim VBC As VBComponent, mti As IntegerSet VBC = NothingLet mti = 0Select Case ModuleTypeIndexCase 1: mti = vbext_ct_StdModule ' standard moduleCase 2: mti = vbext_ct_MSForm ' userformCase 3: mti = vbext_ct_ClassModule ' class moduleEnd SelectIf mti <> 0 ThenOn Error Resume NextSet VBC = wb.VBProject.VBComponents.Add(mti)If Not VBC Is Nothing ThenIf NewModuleName <> "" ThenLet VBC.Name = NewModuleNameEnd IfEnd IfOn Error GoTo 0Set VBC = NothingEnd IfEnd Sub
Nenhum comentário:
Postar um comentário