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??????????
 
You can find the Excel application window and close it programmatically. From MSDN look up "HOWTO: Programmatically Close a Separate Application (Q176391)" The links is this:
Craig, mailto:sander@cogeco.ca

"Procrastination is the art of keeping up with yesterday."

I hope my post was helpful!!!
 
Could you post some of your code? This should be easy to do.
 
lsThisRoutine = "VMCSIIMacro"

Dim xlApp As excel.Application ' Excel Application Object
Dim xlBooks As excel.Workbooks ' Excel.Workbooks

Set xlApp = CreateObject("Excel.Application")

Set xlBooks = Workbooks

'This macro takes the delimited file and opens it into xl for the user to save
xlBooks.OpenText FileName:= _
"C:\tempGrd2File.xls", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True, OtherChar:="+", FieldInfo:=Array(Array(1, 1 _
), Array(2, 1), Array(3, 1), Array(4, 1))
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
ActiveWorkbook.SaveAs FileName:= _
"C:\tempfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

xlBooks.Close
xlApp.Quit

Set xlBooks = Nothing
Set xlApp = Nothing

ExitRoutine:
Exit Sub
 
First thing to note is that you are combining both early and late binding techniques in your handling of the objects. You should use one or the other.
Code:
'Early Binding
Dim xlApp As Excel.Application  
Dim xlBooks As Excel.Workbooks

Set xlApp = New Excel.Application
Set xlBooks = xlApp.Workbooks

'Late Binding
Dim xlApp As Object
Dim xlBooks As Object

Set xlApp = CreateObject("Excel.Application")
Set xlBooks = xlApp.Workbooks
I am assuming that tempGrd2File.xls (+)delimeted file and not a true Excel file?
Code:
'Using Early Binding
Dim xlApp As Excel.Application
Dim xlBook As Workbook
Dim xlSheet As Worksheet

Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.OpenText(FileName:= _
        "C:\tempGrd2File.xls", Origin:=xlWindows, _
        StartRow:=1, DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False _
        , Space:=False, Other:=True, _
        OtherChar:="+", FieldInfo:=Array(Array(1, 1 _
        ), Array(2, 1), Array(3, 1), Array(4, 1)))

Set xlSheet = xlBook.ActiveSheet
xlSheet.Columns("B:B").EntireColumn.AutoFit
xlSheet.Columns("C:C").EntireColumn.AutoFit
xlSheet.Columns("D:D").EntireColumn.AutoFit
    
xlBook.SaveAs FileName:= _
    "C:\tempfile.xls", FileFormat:=xlNormal, _
    Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False
   
xlBooks.Close
xlApp.Quit

Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top