Answers for "vba excel new module"

VBA
1

excel vba add module programmatically

' Add "Microsoft Visual Basic for Applications Extensibility 5.3 library" reference
Sub AddSht_AddCode()
    Dim wb As Workbook
    Dim xPro As VBIDE.VBProject
    Dim xCom As VBIDE.VBComponent
    Dim xMod As VBIDE.CodeModule
    Dim xLine As Long

    Set wb = Workbooks.Add
    With wb
        Set xPro = .VBProject
        Set xCom = xPro.VBComponents("Sheet1")
        Set xMod = xCom.CodeModule
        With xMod
            xLine = .CreateEventProc("Change", "Worksheet")
            xLine = xLine + 1
            .InsertLines xLine, "  Cells.Columns.AutoFit"
        End With
    End With
End Sub
Posted by: Guest on January-21-2021

Code answers related to "VBA"

Browse Popular Code Answers by Language