Hello all,

I'm experiencing a rather frustrating error in both Excel VBA 2003/2007. It only happens sometimes (somewhat rarely), during the below code. I have 5 necessary references, which I can list if need be. Having read the MS help ( http://support.microsoft.com/default...;en-us;Q319832 ) on this topic I feel I may need to "fully qualify" my object references in the below code, but don't really know how to go about doing that...

Here's the code w/ the problem. The below code essentially opens and copies a worksheet from a workbook into the active workbook, then closes the workbook.

vb Code:
  1. Application.DisplayAlerts = False
  2. Dim sfilename As String
  3. sfilename = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls", Title:="N-INDEX")
  4. If sfilename = "False" Then Exit Sub
  5. Dim temp As String
  6. temp = spliceFileNameEnd2(sfilename)
  7. Dim shtnext As Variant
  8. For Each shtnext In Sheets
  9.     If shtnext.name = "pindexCA" Then 'Search/Delete charts w/ same name
  10.         Sheets("pindexCA").Visible = True
  11.         Application.DisplayAlerts = False 'No delete prompt
  12.         Sheets("pindexCA").Delete
  13.     End If
  14. Next shtnext
  15. Workbooks.Open FileName:=sfilename
  16. Dim found As Boolean
  17. found = False
  18. For Each shtnext In Sheets
  19.     If shtnext.name = "pindexCA" Then
  20.         found = True
  21.         Exit For
  22.     End If
  23. Next shtnext
  24. If found = False Then
  25.     Workbooks(temp).Close SaveChanges:=False
  26.     MsgBox ("No P-Index File was found in that file.")
  27.     Sheets.Add
  28.     ActiveSheet.name = "pindexCA"
  29.     Sheets("pindexCA").Visible = xlVeryHidden
  30.     Exit Sub
  31. End If
  32. Sheets("pindexCA").Copy After:=Workbooks(ThisWorkbook.name).Sheets(ThisWorkbook.Sheets.count)
  33. Workbooks(temp).Close SaveChanges:=False
  34. Sheets("pindexCA").Visible = xlVeryHidden
  35. Sheets("Driver").Activate
  36. Application.DisplayAlerts = True