-
August 28th, 2009, 09:04 AM
#1
[RESOLVED] VB6: Excel won't close after sorting
STARTED NEW THREAD************************
I am having an issue where Excel doesn't close when it should. Here is a very simplified version of my code. If I remove the code identified as "Problem Area" then Excel will close as expected at the end of this procedure. If the problem area code is included then Excel will not close. Somehow it seems to be related to the Range still being active which keeps Excel open. Any ideas?
Code:
Dim oExcel As Excel.Application
Dim oWbk As Excel.Workbook
Dim oSht As Excel.Worksheet
Dim oRng As Excel.Range
Set oExcel = New Excel.Application
uploadpath = "C:\Excel File.xls"
Set oWbk = oExcel.Workbooks.Open(uploadpath)
Set oRng = oWbk.Worksheets(1).Range("A8").CurrentRegion
K1Rng = "A8"
K2Rng = "E8"
'*******************************PROBLEM AREA
Range("A8:AC100").Select
Selection.Sort Key1:=Range(K1Rng), Order1:=xlAscending, Key2:=Range(K2Rng) _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
'*******************************END OF PROBLEM AREA
Set oRng = Nothing
Set oSht = Nothing
oWbk.Close SaveChanges:=False
Set oWbk = Nothing
oExcel.Quit
Set oExcel = Nothing
Note: This code works. It opens Excel, loads the spreadsheet, performs the correct sorting on columns A and E. The only thing it doesnt do is close Excel when it is done. If the lines marked above as "Problem Area" are removed, then Excel does close properly. Something in those lines keeps Excel open.
Last edited by Shuja Ali; August 28th, 2009 at 03:32 PM.
Reason: code tags
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
|