Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jul 2006
    Location
    New York City, New York, USA
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Programmatically add code to ThisWorkbook? (2003)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Programmatically add code to ThisWorkbook? (2003)

    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.

  3. #3
    Lounger
    Join Date
    Jul 2006
    Location
    New York City, New York, USA
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Programmatically add code to ThisWorkbook? (20

    Much better idea. I'll do that. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •