title: VBA script runs OK first time, second time errors 'out of range'
body: <p>I have a strange issue with an Access DB running a VBA script, calling an Excel doc to run some fixes before it's used as a linked table.</p>
  
  <p>The strange part is it works perfectly FIRST time the script is run from a freshly opened Access.
  Second time I get the error 'Run-time error '9', Subscript out of range'
  The script fails out on:</p>
  
  <pre><code>Workbooks("Overview Tracker.xlsb").Activate
  </code></pre>
  
  <p>In the IF THEN Sub, testProcessed()
  (I only put that line in to see if activating the Workbook first would help, but it doesn't - either it fails on that line or the next which is the IF line.)</p>
  
  <p>The script runs in this order.
      1. Open the excel doc
      2. Test if processed already or not (check for a cells content)
      3. If processed then pop up a message and quit the Excel document
      4. If not then run the processing and then quit the Excel document</p>
  
  <p>As I said, a freshly opened Access will run this script flawlessly, in either of the cases (processed already or not)  but a second run of the script will always crash out. </p>
  
  <p>I've been trying to figure this out all day, no luck !</p>
  
  <p>Any ideas welcomed !!
  Thanks for your help in advance.</p>
  
  <pre><code>Public Function OpenExcelFixer1()
  Dim xlApp As Excel.Application
  Set xlApp = New Excel.Application
  xlApp.Visible = True
  xlApp.DisplayAlerts = False
  xlApp.Workbooks.Open "C:\Users\....\Overview tracker.xlsb", UpdateLinks:= _
  3
  Call testProcessed
  xlApp.Quit
  End Function
  
  
   Public Sub alreadyDone()
  MsgBox "This file has already been processed", vbExclamation, "Overview Tracker already fixed"
  Excel.Application.Quit
   End Sub
  
  
  Public Sub fixProcess()
  ActiveWorkbook.Save
  Sheets("OVERVIEW").Select
  Rows("1:1").Select
  Selection.Delete Shift:=xlUp
  Columns("A:I").Select
  Selection.NumberFormat = "@"
  Columns("Q:X").Select
  Selection.NumberFormat = "[$-F800]dddd, mmmm dd, yyyy"
  Sheets("SHIPPING").Select
  Rows("1:1").Select
  Selection.Delete Shift:=xlUp
  Columns("A:I").Select
  Selection.NumberFormat = "@"
  Columns("Q:X").Select
  Selection.NumberFormat = "[$-F800]dddd, mmmm dd, yyyy"
  Sheets("Dell Update").Select
  Range("G1").Select
  ActiveCell.FormulaR1C1 = "PROCESSED"
  ActiveWorkbook.Save
  ActiveWorkbook.Close
  Excel.Application.Quit        
  End Sub
  
  
  Public Sub testProcessed()
  Workbooks("Overview Tracker.xlsb").Activate
  If Workbooks("Overview Tracker.xlsb").Sheets("Update").Range("G1").Value = "PROCESSED" Then
   Call alreadyDone
  Else
   Call fixProcess
  End If
  End Sub
  </code></pre>