Consulting

Results 1 to 7 of 7

Thread: Excel Template mode

  1. #1

    Excel Template mode

    Hi all,

    I am trying to create some VBA code that is only activated from the template when a new instance is created.

    I am using Excel 2003.

    I've tried searching, but get so many hits I'd be here all day!

    Maybe this is something straight forward that I'm not aware of, but is it possible to detect in VBA when you are in Template mode??

    Thanks
    Andy

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What do you mean by in template mode?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    The File is open as a template, rather than the file is open as a document.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    When you open a template, it just creates a standard Excel workbook (based upon that template). If you actually mean the template is opened, that is not new based on that template, just check its file type.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    There may be a better way, but this is what I worked out:

    [vba] Dim FileName As String
    Dim Extension As String

    FileName = ActiveWorkbook.Name

    Extension = LCase(Right(FileName, 3))

    If Extension = "xls" Then
    [/vba]

  6. #6
    Had to change it to:

    [VBA]If Not Extension = "xlt" Then[/VBA]

    Quirkily enough Excel doesn't add the extension until the file is saved! lol

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Annodomini2
    Had to change it to:

    [VBA]If Not Extension = "xlt" Then[/VBA]
    Better to use

    [vba]Extension = LCase(Right(FileName, Len(FileName) - InStrRev(FileName, ".")))

    If Not Extension Like "xlt*" Then [/vba]

    Quote Originally Posted by Annodomini2
    Quirkily enough Excel doesn't add the extension until the file is saved! lol
    Until it is saved, there is no type.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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