Calling another workbook

  • Thread starter Patrick Simonds
  • Start date
P

Patrick Simonds

The code below is run by clicking on a UserForm button which is part of
WorkBook Vacation.xls. Is there any way to perform this with out making
Employee List.xls active or to return me to where I was in Vacation.xls
after the sort is complete?


Sub PT_Driver_Last_Name_Sort()
'
' Macro1 Macro
' Macro recorded 12/20/2005 by Cathy Baker
'
'Sort by Paratransit Drivers Last Name

Windows("Employee List.xls").Activate
Worksheets("Employee_List").Range("AA1").Value = 2

Dim wks As Worksheet
Set wks = Worksheets("Employee_List")
With wks.Range("A1:Z300")
..Sort Key1:=wks.Range("E2"), Order1:=xlAscending, Key2:=wks.Range("F2") _
, Order2:=xlAscending, Key3:=wks.Range("A2"), Order3:=xlAscending,
Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=
_
xlSortNormal
End With

End Sub
 
T

Tom Ogilvy

Remove this line:

Windows("Employee List.xls").Activate


Sub PT_Driver_Last_Name_Sort()
'
' Macro1 Macro
' Macro recorded 12/20/2005 by Cathy Baker
'
'Sort by Paratransit Drivers Last Name


Worksheets("Employee_List").Range("AA1").Value = 2

Dim wks As Worksheet
Set wks = Worksheets("Employee_List")
With wks.Range("A1:Z300")
...Sort Key1:=wks.Range("E2"), Order1:=xlAscending, Key2:=wks.Range("F2") _
, Order2:=xlAscending, Key3:=wks.Range("A2"), Order3:=xlAscending,
Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=
_
xlSortNormal
End With

End Sub
 
T

Tom Ogilvy

Lets try again -- I hit send too soon.

Sub PT_Driver_Last_Name_Sort()
'
' Macro1 Macro
' Macro recorded 12/20/2005 by Cathy Baker
'
'Sort by Paratransit Drivers Last Name

Dim bk as Workbook
set bk = Workbooks("Employee List.xls").
bk.Worksheets("Employee_List").Range("AA1").Value = 2

Dim wks As Worksheet
Set wks = bk.Worksheets("Employee_List")
With wks.Range("A1:Z300")
.Sort Key1:=wks.Range("E2"), Order1:=xlAscending, _
Key2:=wks.Range("F2"),Order2:=xlAscending, _
Key3:=wks.Range("A2"), Order3:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
End With

End Sub
 
P

Patrick Simonds

The problem with that is that Vaction.xls is the active workbook and this
code is performing a sort on Employee List.xls.
 
P

Patrick Simonds

Disregard I posted before your update.

Patrick Simonds said:
The problem with that is that Vaction.xls is the active workbook and this
code is performing a sort on Employee List.xls.
 
P

Patrick Simonds

Thank you that did the trick.

Tom Ogilvy said:
Lets try again -- I hit send too soon.

Sub PT_Driver_Last_Name_Sort()
'
' Macro1 Macro
' Macro recorded 12/20/2005 by Cathy Baker
'
'Sort by Paratransit Drivers Last Name

Dim bk as Workbook
set bk = Workbooks("Employee List.xls").
bk.Worksheets("Employee_List").Range("AA1").Value = 2

Dim wks As Worksheet
Set wks = bk.Worksheets("Employee_List")
With wks.Range("A1:Z300")
.Sort Key1:=wks.Range("E2"), Order1:=xlAscending, _
Key2:=wks.Range("F2"),Order2:=xlAscending, _
Key3:=wks.Range("A2"), Order3:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Suppressing a screen 4
Runtime error 1004 Application-defined or object defined error" on data sort 1
What am I doing wrong? 6
Sort error? 2
sort range 0
Writing a Sort Macro 4
Sort by range 15
sorting columns 5

Top