|
-
Dec 12th, 2002, 08:40 AM
#1
Thread Starter
Junior Member
Help with Excel
I searched the entire forum and couldn't get a good answer. I have created an application which stores the information in an Excel file.
I have created the Excel object inside a form. On the click of a command button an excel file is created and the data is saved. There seems to be no problem if two or more excel file is created. But when I reload that form again and try to create excel file. It gives "_Global failed". The excel application quits only when the program is closed
The code is
Dim xls As Object
Private Sub cmd_Make_Click()
xls.Workbooks.Add
xls.Workbooks(1).Activate
' Code to write to the Excel sheet
Worksheets("Sheet1").Cells(1, 1).Value = "Sl. No"
ActiveWorkbook.SaveAs App.Path & "\Excel\" & strFileName, xlExcel9795
xls.ActiveWorkbook.Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
xls.Quit
Set xls = Nothing
End Sub
Last edited by cool_coolioin; Dec 13th, 2002 at 08:18 AM.
-
Dec 12th, 2002, 08:58 AM
#2
VB Code:
'Why are you not using the Excel object library reference?
[b]Private[/b] xlsQuotation As [b]Excel.Application[/b]
'I take it you've got code already to set the object?
[b]Private Sub form_activate()
me.show
set xlsQuotation = new Excel.Application
End Sub[/b]
Private Sub cmd_Make_Click()
' The above variable is xlsQuotation, yet the below code
' references a "xls" named Excel object variable...
[b]xlsQuotation.[/b]Workbooks.Add
[b]xlsQuotation.[/b]Workbooks(1).Activate
'You haven't referenced the Excel object that the sheet is part of
[b]xlsQuotation.[/b]Worksheets("Sheet1").Cells(1, 1).Value = "Sl. No"
'Ditto Here
[b]xlsQuotation.[/b]ActiveWorkbook.SaveAs App.Path & _
"\Excel\" & strFileName, xlExcel9795
[b]xlsQuotation.[/b].ActiveWorkbook.Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
[b]xlsQuotation.[/b].Quit
'You haven't put the object name in here
Set [b]xlsQuotation[/b] = Nothing
End Sub
Last edited by alex_read; Dec 12th, 2002 at 09:02 AM.
-
Dec 13th, 2002, 08:00 AM
#3
Thread Starter
Junior Member
There has been some typing mistake
But it doesn't still work. The Excel application is not closed
-
Dec 13th, 2002, 11:16 AM
#4
Frenzied Member
If Excel doesn't close, then you have not set all references to Excel Objects to = Nothing.
NOTE There are some references that Excel may produce on your behalf (typically wen using .RANGE commands), so you will need to de-bug most carefully.....
OR if you are really lucky, post all of your code here, and someone may see the error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|