P
Patrick Simonds
I recorded the code below to sort my list of employees, and on it's own it
works great. My problem is that while I have WorkBook open it is not the
Active WorkBook. I am calling the sort routine from within another WorkBook.
Private Sub CommandButton1_Click()
'Sort by Fixed Route Driver Names
Application.Run "EmployeeList.xls!FRDSort"
End Sub
=======================================================
Sub FRDSort()
'Sort by Fixed Route Drivers Names
Module1.Disable_Events
Module1.UnprotectWorkSheet
Range("B1").Value = "3"
ActiveWorkbook.Worksheets("Employee_List").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Employee_List").Sort.SortFields.Add
Key:=Range( _
"F2:F300"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=
_
xlSortNormal
ActiveWorkbook.Worksheets("Employee_List").Sort.SortFields.Add
Key:=Range( _
"D2300"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=
_
xlSortNormal
With ActiveWorkbook.Worksheets("Employee_List").Sort
.SetRange Range("A2:I300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
Module1.Enable_Events
Module1.ProtectWorkSheet
End Sub
works great. My problem is that while I have WorkBook open it is not the
Active WorkBook. I am calling the sort routine from within another WorkBook.
Private Sub CommandButton1_Click()
'Sort by Fixed Route Driver Names
Application.Run "EmployeeList.xls!FRDSort"
End Sub
=======================================================
Sub FRDSort()
'Sort by Fixed Route Drivers Names
Module1.Disable_Events
Module1.UnprotectWorkSheet
Range("B1").Value = "3"
ActiveWorkbook.Worksheets("Employee_List").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Employee_List").Sort.SortFields.Add
Key:=Range( _
"F2:F300"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=
_
xlSortNormal
ActiveWorkbook.Worksheets("Employee_List").Sort.SortFields.Add
Key:=Range( _
"D2300"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=
_
xlSortNormal
With ActiveWorkbook.Worksheets("Employee_List").Sort
.SetRange Range("A2:I300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
Module1.Enable_Events
Module1.ProtectWorkSheet
End Sub