Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Template vs workbook (XL97, WinNT4)

    I know this has got to be a stupid question, so I apologise in advance <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>, but I can't find the answer for the life of me!

    How do you define macros that are to be run when a template creates a workbook, versus ones that are to run every time the resulting workbook is opened?! I've got the workbook_open sub, to run when the workbook is opened, but I can't find the equivalent of the 'document_new' that you'd use in Word! <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>

    Someone please put me out of my misery!

    TIA
    Beryl M


  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Template vs workbook (XL97, WinNT4)

    If a new workbook is created by "opening" a template, the workbook has not been saved before.

    So:

    Private Sub Workbook_Open()
    If instr(thisworkbook.name,"xlt")>0 then
    'Opened template itself, do stuff
    Exit sub
    End If
    If Thisworkbook.Path="" then
    'File based on template and not saved, do stuff
    Else
    'File Saved before, do other stuff!
    End If
    End Sub
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Template vs workbook (XL97, WinNT4)

    Jan, you're brilliant! I must admit I hadn't got as far as lateral thinking with this one, I just assumed there must be an equivalent to Word's document_new somewhere in XL - but now you say it, it's obvious!

    Many thanks! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


Posting Permissions

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