XLA routines: EE_ExportSheetToXLS

Nick's picture
EE_ExportSheetToXLS exports a worksheet to an XLS
Function EE_ExportSheetToXLS(strSheetName As String, strFilePath As String) As Boolean
'- takes a sheet name
'- takes a FullFilePath
'- creates new wb
'- delete existing file
'- sheet.copy (new wb)
'- saveas (FilePath)
'- close
'- returns True if success
    Dim wbkNew              As Workbook
    Dim strNewFullFilePath  As String
 
'http://excelexperts.com/xla-routines-eeExportSheetToXLS    for updates on this function

    ThisWorkbook.Worksheets(strSheetName).Copy
    Set wbkNew = ActiveWorkbook
 
    strNewFullFilePath = Replace(strFilePath & "\" & strSheetName & ".xls", "\\", "\")
    On Error Resume Next
        Kill strNewFullFilePath
    On Error GoTo 0
 
    On Error GoTo ErrH
        Application.DisplayAlerts = False
        wbkNew.SaveAs FileName:=strNewFullFilePath, FileFormat:=56
    On Error GoTo 0
 
    wbkNew.Close False
    Application.DisplayAlerts = True
    EE_ExportSheetToXLS = True
 
    Exit Function
ErrH:
    If Not wbkNew Is Nothing Then
        wbkNew.Close False
    End If
    EE_ExportSheetToXLS = False
End Function