leishtheman

New Member
Joined
Oct 1, 2007
Messages
32
Hello

Having tried unsuccessfully to find a solution to the below issue on both google and old threads in this forum I kindly request any suggestions as to how to solve this problem.

I'm simply trying to sort a range in an Excel file from Access, but it's erroring with everything I try. My code is below with my attempts commented out. None of them work. I need to connect to Excel via late binding as our user community as various different versions of MS Office. Any ideas what I'm doing wrong????

Many thanks in advance,

Andy




Dim xl As Object 'late binding
Dim xlb As Object 'late binding
Dim xlw As Object 'late binding
Dim xlr As Object

Set xl = CreateObject("Excel.Application")
Set xlb = xl.Workbooks.Open("C:\Users\leishmana\Desktop\q_PermRecruitment_AP11.xls")
Set xlw = xlb.worksheets("q_PermRecruitment_Periodic")
Set xlr = xlw.range("i2:i14")

xl.Visible = True
xlb.Activate
xlw.Activate

With xlb.worksheets(xlw.Name).Sort
.sortfields.Clear
'.sortfields.Add Key:=.range("I2:I14"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
'.sortfields.Add Key:=xlb.Worksheets(xlw.Name).range("i2:i14"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
'.sortfields.Add Key:=xlr, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
'.sortfields.Add Key:=xlw.range("i2:i14"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
'.sortfields.Add Key:=activeworkbook.xlw.range("i2:i14"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
'.sortfields.Add Key:=activeworkbook.worksheets(xlw).range("i2:i14"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
'.sortfields.Add Key:=activeworkbook.worksheets("q_PermRecruitment_Periodic").range("i2:i14"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
'.sortfields.Add Key:=xl.activeworkbook.worksheets("q_PermRecruitment_Periodic").range("i2:i14"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
'.sortfields.Add Key:=xl.xlb.xlw.range("i2:i14"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.Apply
End With
 
Last edited:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,215,471
Messages
6,125,000
Members
449,202
Latest member
Pertotal

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top