Consulting

Results 1 to 5 of 5

Thread: xlsm or xltm file extension

  1. #1

    xlsm or xltm file extension

    I'm trying to tell whether user has just opened a template file or a macro-enabled workbook.

    If I use activeworkbook.fullname:

    for the .xlsm I would get: test file.xlsm

    but the template just gives: test file template1

    So the template does not give the file extension (.xltm) and the template file has been renamed template1.

    I assume this is because template1 is a newly-created file and therefore has not been saved.

    So what would be the best way to test which file has been opened ?

    Perhaps something like:

    If the active book has the file extension ".xlsm" then exit
    but
    If the active book contains the string "template1" in the workbook name
    Then do something else

    Many thanks.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    So what would be the best way to test which file has been opened ?
    I think you are confusing ActiveWorkbook with Opened workbook and New Workbook.

    The ActiveWorkbook is merely the one you are looking at on the screen. It doesn't matter if it is a CSV file, a TXT file, an XLSM, XLST, XLSX, XLSB, or a brand new file that has never been saved.

    If you Open a Workbook, it will have an Extension in its' name. Therefor you can usually tell the difference between any saved workbook and a new unsaved workbook programmatically with

    If Instr("Name of Book", ".") <> 0 Then 'Book has been saved.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    ThisWorkbook.FileFormat might be safer


    Probably requires a little investigation. For example, if I open a XLMT to edit, .FileFormat= xlOpenXMLTemplateMacroEnabled (= 53) and a XLSX .FileFormat= xlOpenXMLWorkbookMacroEnabled (52)

    Look at

    https://msdn.microsoft.com/en-us/lib...ileformat.aspx

    .FileFormat= 0 = Just created from template = Not saved
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Sam & Paul, many thanks.

    Sam - yes my mistake (doh), it will be the activeworkbook that needs checking.

    Paul - I had not known of FileFormat - I will investigate.

    Thanks to you both.

    ps: how to mark a post as 'solved' please ?

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    ps: how to mark a post as 'solved' please ?
    Above Post #1, Thread Tools, you get a "Mark Solved" radio button
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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