Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving a .xlt to a .xls

Status
Not open for further replies.

TAMU

MIS
Joined
Jun 24, 2004
Messages
9
Location
US
Is it possible to set it up so when you have a .xlt file open and do a saveas that it would default to a .xls file in Excel 2000.
 
That's a good feature in older versions of Excel that has been removed from newer versions. Here's a macro that restores the functionality. If the file is a .xlt template and the user tries to save it--the macro displays a Save As dialog window with the same folder and filename (only with .xls extension). If the file already has a .xls extension, then the save proceeds normally.

This macro needs to go in the ThisWorkbook code pane of the template.

If you want to change the default behavior of Excel, then you can create a class module for the Excel application and trap the Save event. I don't recommend this latter approach because users can become confused if things don't behave the way that is expected--but it is possible.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'If file is a .xlt, display Save As dialog window. Default save with the same name and folder, only with .xls extension
On Error GoTo ErrorSub
Dim strFilename As String
Application.EnableEvents = False
strFilename = ActiveWorkbook.Name
If LCase(Right(strFilename, 3)) <> "xlt" Then
    Application.EnableEvents = True
    Exit Sub
End If
strFilename = ActiveWorkbook.Path & Application.PathSeparator & Left(strFilename, Len(strFilename) - 3) & "xls"
strFilename = Application.GetSaveAsFilename(strFilename, "Excel Workbook (*.xls), *.xls")
If LCase(strFilename) <> "false" Then
    ThisWorkbook.SaveAs (strFilename)
End If
    
ErrorSub:
    If Err <> 0 Then
        MsgBox Err.Description, vbCritical, "Error!"
    End If
    Application.EnableEvents = True
    Cancel = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top