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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing excel from Visual Basic

Status
Not open for further replies.

GODSWL

Programmer
Apr 5, 2002
11
0
0
US
After I close all workbooks, quit application and set all objects to nothing; -Excel app is still running. What else can I do to terminate application??????????
 
Are you using VBA from within Excel of VB, external to Excel? Skip,
metzgsk@voughtaircraft.com
 
Could you also toss in some of your code? You should be able to close everyting without any difficulty.
 
heres an example of what i am doing, and i have the same problem . Note also, that during the xlMacro, i am saving the workbook to a folder - perhaps this is the cause ?:

Function Make_Report(rLandcode as string, rFileName As string)
Dim xl As Excel.Application
Set xl = New Excel.Application
xl.Visible = True
xl.Workbooks.Add
With xl ' VBA Macro
''''''''
''''''''
End With
xl.ActiveWorkbook.Close
xl.Application.Quit
Set xl = Nothing
End Function
 
---------------------------------------
Option Explicit

Dim ExcelApp As Excel.Application
Dim ExcelCht As Excel.Chart
Dim ExcelSht As Excel.Worksheet
Dim ExcelWkb As Excel.Workbook
Dim MyExcel As Boolean

Private Sub Command1_Click()

On Error Resume Next

Err.Clear

Set ExcelApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
Set ExcelApp = CreateObject(&quot;Excel.Application&quot;)
If Err.Number <> 0 Then
MsgBox &quot;Error: &quot; & Err.Description
Else
MyExcel = True

End If

Else
MyExcel = False

End If

ExcelApp.Visible = True

Check1.Value = vbChecked
Command2.SetFocus

End Sub

Private Sub Command10_Click()

Unload Me

End Sub

Private Sub Command2_Click()

Set ExcelWkb = ExcelApp.Workbooks.Add
Set ExcelSht = ExcelWkb.Worksheets(1)

Check2.Value = vbChecked
Command3.SetFocus

End Sub

Private Sub Command3_Click()

Dim i As Integer
Dim j As Integer

For i = 1 To 4
For j = 1 To 10
ExcelSht.Cells(j, i) = Rnd() * 100
Next j
Next i

Check3.Value = vbChecked
Command4.SetFocus

End Sub

Private Sub Command4_Click()

ExcelSht.Range(&quot;A1:D10&quot;).NumberFormat = &quot;0.00&quot;

Check4.Value = vbChecked
Command5.SetFocus

End Sub

Private Sub Command5_Click()

Set ExcelCht = ExcelWkb.Charts.Add
ExcelCht.ChartType = xlLineMarkers
ExcelCht.SetSourceData ExcelSht.Range(&quot;A1:D10&quot;), xlColumns
ExcelCht.HasTitle = True
ExcelCht.ChartTitle.Characters.Text = &quot;My Data&quot;
ExcelCht.Axes(xlCategory, xlPrimary).HasTitle = True
ExcelCht.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = &quot;X-Axis&quot;
ExcelCht.Axes(xlValue, xlPrimary).HasTitle = True
ExcelCht.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = &quot;Data Series&quot;

Check5.Value = vbChecked
Command6.SetFocus

End Sub

Private Sub Command6_Click()

ExcelCht.ChartArea.Select
ExcelCht.ChartArea.Copy

Image1.Picture = Clipboard.GetData(vbCFBitmap)

Check6.Value = vbChecked
Command7.SetFocus

End Sub

Private Sub Command7_Click()

If Len(Dir(App.Path & &quot;\test.xls&quot;)) <> 0 Then
Kill App.Path & &quot;\test.xls&quot;
End If

ExcelWkb.SaveAs App.Path & &quot;\test.xls&quot;

Check7.Value = vbChecked
Command8.SetFocus

End Sub

Private Sub Command8_Click()

ExcelWkb.Close False

Check8.Value = vbChecked
Command9.SetFocus

End Sub

Private Sub Command9_Click()

If MyExcel Then
ExcelApp.Quit
End If

Check9.Value = vbChecked
Command10.SetFocus

End Sub

Private Sub Form_Load()

Randomize

End Sub
---------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top