fizbim
09-03-2002, 06:42 PM
Although it's a small comfort, I see that I'm not the only one who has this problem (ie - "Excel Wont Quit").
I've worn off the ends of my fingers by trying different sequences and methods of my code with no positive results. MSDN has no useful information either (that I could find). Here is my code again (for those who missed it before).
Public Sub NewWorkbook()
Dim xlap As Excel.Application
Dim xlwb As Excel.Workbooks
Dim xlws As Excel.Worksheet
Set xlap = New Excel.Application
xlap.DisplayAlerts = False
'**************************************
' Add new workbook
'**************************************
xlap.SheetsInNewWorkbook = 1
xlap.Workbooks.Add
Set xlwb = xlap.Workbooks
'**************************************
' Name the first worksheet. Then add
' 2 more worksheets and name them
'**************************************
xlap.Worksheets.Item(1).Name = "-51"
xlap.Worksheets.Add After:=Worksheets(1)
xlap.Worksheets.Item(2).Name = "-52"
xlap.Worksheets.Add After:=Worksheets(2)
xlap.Worksheets.Item(3).Name = "-53"
'*************************************
' Write test value to first cell in
' each sheet
'*************************************
Set xlws = xlap.Worksheets("-51")
xlws.Cells(1, 1) = "Test Sheet 1"
Set xlws = xlap.Worksheets("-52")
xlws.Cells(1, 1) = "Test Sheet 2"
Set xlws = xlap.Worksheets("-53")
xlws.Cells(1, 1) = "Test Sheet 3"
'*************************************
' Make the top sheet active
'*************************************
xlwb.Item(1).Worksheets(1).Activate
'*************************************
' Save new workbook and prepare to
' exit
'*************************************
xlap.ActiveWorkbook.SaveAs "C:\test2.xls"
xlap.DisplayAlerts = True
xlwb.Close
xlap.Quit
'*************************************
' Destroy the objects and exit
'*************************************
Set xlwb = Nothing
Set xlws = Nothing
Set xlap = Nothing
End Sub
Simply put - This just doesn't work and it ought to. Maybe I'm dense, but I just don't see it.
Please help !
Fiz
I've worn off the ends of my fingers by trying different sequences and methods of my code with no positive results. MSDN has no useful information either (that I could find). Here is my code again (for those who missed it before).
Public Sub NewWorkbook()
Dim xlap As Excel.Application
Dim xlwb As Excel.Workbooks
Dim xlws As Excel.Worksheet
Set xlap = New Excel.Application
xlap.DisplayAlerts = False
'**************************************
' Add new workbook
'**************************************
xlap.SheetsInNewWorkbook = 1
xlap.Workbooks.Add
Set xlwb = xlap.Workbooks
'**************************************
' Name the first worksheet. Then add
' 2 more worksheets and name them
'**************************************
xlap.Worksheets.Item(1).Name = "-51"
xlap.Worksheets.Add After:=Worksheets(1)
xlap.Worksheets.Item(2).Name = "-52"
xlap.Worksheets.Add After:=Worksheets(2)
xlap.Worksheets.Item(3).Name = "-53"
'*************************************
' Write test value to first cell in
' each sheet
'*************************************
Set xlws = xlap.Worksheets("-51")
xlws.Cells(1, 1) = "Test Sheet 1"
Set xlws = xlap.Worksheets("-52")
xlws.Cells(1, 1) = "Test Sheet 2"
Set xlws = xlap.Worksheets("-53")
xlws.Cells(1, 1) = "Test Sheet 3"
'*************************************
' Make the top sheet active
'*************************************
xlwb.Item(1).Worksheets(1).Activate
'*************************************
' Save new workbook and prepare to
' exit
'*************************************
xlap.ActiveWorkbook.SaveAs "C:\test2.xls"
xlap.DisplayAlerts = True
xlwb.Close
xlap.Quit
'*************************************
' Destroy the objects and exit
'*************************************
Set xlwb = Nothing
Set xlws = Nothing
Set xlap = Nothing
End Sub
Simply put - This just doesn't work and it ought to. Maybe I'm dense, but I just don't see it.
Please help !
Fiz