• Programmatically add code to ThisWorkbook? (2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Programmatically add code to ThisWorkbook? (2003)

    Author
    Topic
    #443473

    Hi All,
    I haven’t done much with VB Components before. The macro I’m working on creates a new data book, and it would be ideal to have it put a workbook activate and workbook deactivate event on the ThisWorkbook module, just to assign and unassign OnKeys.. I’ve messed around a bit, modifying some code from Chip Pearson’s site, and managed to crash Excel with amazing consistency.

    The text I was looking to put in ThisWorkbook is

    “Option Explicit” & Chr(13) & _
    “Private Sub Workbook_Activate()” & Chr(13) & _
    “Application.OnKey “”{f10}””, “”SortTable””” & Chr(13) & _
    “End Sub” & Chr(13) & _
    Chr(13) & _
    Private Sub Workbook_Deactivate()” & Chr(13) & _
    “Application.OnKey “”{f10}””” & Chr(13) & _
    “End Sub” & Chr(13)

    What’s the best way to do this? Or is it foolish to attempt?
    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #1069766

      I think it’d be safer to create a template with the necessary code already built in, and to create a new workbook from the template.

    Viewing 0 reply threads
    Reply To: Programmatically add code to ThisWorkbook? (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: