Hi,
I have a function that creates a excelsheet, works OK but it doesn't close excel afterwards. I'm doing something not rigth, but even after reading several posts (...about Having incorrect or non-fully qualified references etc) I have not figured it out. Is ther someone who can tell me what it is that i'm doing wrong here?
Maarten
I have a function that creates a excelsheet, works OK but it doesn't close excel afterwards. I'm doing something not rigth, but even after reading several posts (...about Having incorrect or non-fully qualified references etc) I have not figured it out. Is ther someone who can tell me what it is that i'm doing wrong here?
Code:
Public Function CreateExcelWorkbook(ByVal strWorkbookName As String) As Boolean
Dim appExcel As Excel.Application
Dim wbkWorkbook As Excel.Workbook
Dim wksWorkSheet As Excel.Worksheet
On Error GoTo CreateExcelError
CreateExcelWorkbook = True
Set appExcel = CreateObject("Excel.Application")
appExcel.Application.Visible = True 'False
Set wbkWorkbook = appExcel.Workbooks.Add
Set wksWorkSheet = wbkWorkbook.Worksheets.Add
wksWorkSheet.SaveAs FileName:=strWorkbookName
CreateExcelExit:
With appExcel
Workbooks(wbkWorkbook.name).Close
appExcel.Application.Quit
End With
Set wksWorkSheet = Nothing
Set wbkWorkbook = Nothing
Set appExcel = Nothing
Exit Function
CreateExcelError:
CreateExcelWorkbook = False
MsgBox Err.Description
GoTo CreateExcelExit
End Function
Maarten