PC Review


Reply
Thread Tools Rate Thread

How to change to not active workbook

 
 
Patrick Simonds
Guest
Posts: n/a
 
      8th Oct 2006
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


 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      8th Oct 2006
Change ActiveWorkbook with a reference to the workbook where you want to do
the work

Workbooks("MyOtherBook.xls")

instead of ActiveWorkbook.

I can't say for the Module.Unprotectworksheet code or the Disable_Events
code. But if it is set up to work on the activeworkbook, you would need
changes there also.

--
Regards,
Tom Ogilvy



"Patrick Simonds" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Cursor Image if Workbook is not the Active Window RyanH Microsoft Excel Programming 2 12th Sep 2008 01:21 PM
Closing Hidden Workbook when Active Workbook is Closed =?Utf-8?B?U3VzYW5LNTIx?= Microsoft Excel Programming 5 24th Sep 2005 12:27 AM
Undesired change of active workbook keithb Microsoft Excel Programming 3 16th Aug 2005 07:15 AM
copy worksheet from closed workbook to active workbook using vba =?Utf-8?B?bWFuZ28=?= Microsoft Excel Worksheet Functions 6 9th Dec 2004 07:55 AM
Preventing opening workbook inside active workbook. Serge Microsoft Excel Programming 2 4th Nov 2003 07:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:49 PM.