I've always wondered how to make one of those neat little plug-ins for Visual Basic 6.0 that insert code into the file you're working on. I'm no master, but I finally started checking about and have it proof-of-concepted, at least.

In all of my vb apps, I like to use a separate module to handle errors, in case I want to start changing the way they're handled. By having it pulled out, I've got one place that I have to alter to make error handling change globally. But scrawling that error handling crap the same way every time I'd add a method drove me crazy.

Enter the "AddIn" project in VB6. When you start a new project, select "AddIn". Add a button called cmdInsertText (for this example). Insert this code:

' Insert text into code module.
Private Sub cmdInsertText_Click()
    Dim vbComp As VBComponent
    Dim strToInsert As String
    
    Set vbComp = VBInstance.ActiveVBProject.VBE.SelectedVBComponent
    
    strToInsert = vbNewLine & _
        "public sub " & Me.Text1.Text & vbNewLine & _
        "on error goto errHand" & vbNewLine & _
        vbNewLine & _
        vbNewLine & _
        "exit sub" & vbNewLine & _
        "errHand:" & vbNewLine & _
        vbTab & _
        "Call mdlErr.errp(""" & vbComp.Name & "." & Me.Text1.Text & """, err)" & _
        vbNewLine & _
        "end sub"

    vbComp.CodeModule.AddFromString strToInsert
End Sub


... and then build it. Voila. It's in the Add-Ins menu for all your other VB projects, and it'll insert a new sub at the top of your current file. Woohoo!

Needs some extra stuff to be really useful, but a decent start. Got most of what I needed from the VB6 help topic "Manipulating Code with Add-Ins" and F2.