Spare Post for misc. notes













Before doing this, select File > Options > Trust Center > Trust Center Settings... > Macro Settings.
Make sure that the check box 'Trust access to the VBA project object model' is ticked, then click OK.

Use the following as starting point and edit it as you like.

Code:
Sub CreateXLSM()
    Dim wbk As Workbook
    Dim vbc As Object ' VBComponent
    Dim mdl As Object ' CodeModule
    Set wbk = Workbooks.Add(xlWBATWorksheet)
    Set vbc = wbk.VBProject.VBComponents.Add(1) ' vbext_ct_StdModule
    Set mdl = vbc.CodeModule
    mdl.AddFromString _
        "Sub Test()" & vbCrLf & _
        "    MsgBox ""Hello World!"", vbInformation" & vbCrLf & _
        "End Sub"
    wbk.SaveAs Filename:="Test.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    wbk.Close
End Sub





https://eileenslounge.com/viewtopic.php?f=30&t=36283



http://www.excelfox.com/forum/showth...0849#post10849







Rem Ref
' http://www.eileenslounge.com/viewtopic.php?f=30&t=31395
' http://www.cpearson.com/excel/vbe.aspx
http://www.excelfox.com/forum/showth...ll=1#post10971
http://www.excelfox.com/forum/showth...1011#post11011