|
-
August 28th, 2009, 05:29 PM
#2
Re: VB6: Excel won't close after sorting
Good News! I solved my own problem(s). Basically had to make sure that my Range and Selection statements had the appropriate parent objects specified. Corrected code is shown below:
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 oSht = oWbk.Worksheets(1) '<---- this was added also
Set oRng = oWbk.Worksheets(1).Range("A8").CurrentRegion
K1Rng = "A8"
K2Rng = "E8"
'*******************************PROBLEM AREA
oSht.Range("A8:AC100").Select
oExcel.Selection.Sort Key1:=oSht.Range(K1Rng), Order1:=xlAscending, Key2:=oSht.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
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
|