Can macro create another macro?
If it is an event macro, use something like
Dim iStartAs Long
With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
iStart = .CreateEventProc("BeforeSave", "Workbook") + 1
.InsertLines iStart, _
"Dim ans" & vbCrLf & _
" ans = Msgbox( ""All OK"",vbYesNo)" & vbCrLf & _
" If ans = vbNo Then Cancel = True"
End With
If it just another macro in Module1 say, then use
Dim iNext As Long
With ThisWorkbook.VBProject.VBComponents("Module1").Cod eModule
iNext = .CountOfLines + 1
.InsertLines iNext, _
"Sub myProc()" & vbNewLine & _
" Msgbox ""Tesing new procedure"" " & vbNewLine & _
"End Sub"
End With
Thanks! I'll try it out
Reg. VK
|