title: Excel 2003: Programmatic sort of sheet in different workbook
body: <p>From the current workbook, I want to open a sheet in the source workbook, turn off any filtering that may be present, sort by one column, then another, then another.  Am getting 1004 and other errors.  This needs to run on 2003.  Any help will be appreciated!</p>
  
  <pre><code>Dim WB As Workbook, WasWBOpen As Boolean, srcfile As String, srcpath As String,    
  onecol as integer, twocol as integer, thrcol as integer
  
  srcpath = "blahblah"
  srcfile = "blah.xls"
  
  On Error Resume Next
  Set WB = Workbooks(srcfile)
  WasWBOpen = True
  On Error GoTo 0
  If WB Is Nothing Then
  Set WB = Workbooks.Open(srcpath &amp; srcfile, UpdateLinks:=False)
  WasWBOpen = False
  End If
  
  'code before this opens source wkbook
  
  lstrow = Worksheets("Sheet1").UsedRange.Row - 1 + Worksheets("Sheet1").UsedRange.Rows.Count
  lstcol = Worksheets("Sheet1").UsedRange.Column - 1 + Worksheets("Sheet1").UsedRange.Columns.Count
  
  onecol=3
  twocol=5
  thrcol=8
  
  With WB.Sheets("Sheet1")
  
  .AutoFilterMode = False
  .Range("1:1").AutoFilter
  'Here's where error occurs--
  .Range(Cells(1, 1), Cells(lstrow, lstcol)).Sort _
      Key1:=Columns(onecol), Order1:=xlAscending, _
      Key2:=Columns(twocol), Order2:=xlAscending, _
      Key3:=Columns(thrcol), Order3:=xlAscending, Header:=xlYes
  
  End With
  
  If WasWBOpen = False Then
  WB.Close
  End If
  </code></pre>