"Amanda" <(E-Mail Removed)> wrote in message
news:ec593e5f-ac60-4f40-ab58-(E-Mail Removed)...
> below is my code.
> if i run it once, it works. if i run it twice, it does not. if i run
> it the third time, it does.
> obviously, something is ticking on and off.
> any help would be great
> thanks!
>
> With Application.FileSearch
> .NewSearch
>
> .LookIn = "C:\Documents and Settings\ga1790-1\Desktop
> \Holder"
> .Filename = "R2.xls"
> If .Execute > 0 Then
> For lCount = 1 To .FoundFiles.Count
>
> Set wbresults =
> Excel.Application.Workbooks.Open(Filename:=.FoundFiles(lCount),
> UpdateLinks:=0)
>
>
> Killer = .FoundFiles(lCount)
> Killer = Split(Killer, "\")
> Killer = Killer(UBound(Killer))
>
> Workbooks(Killer).Close False
>
> Kill .FoundFiles(lCount)
>
> Next lCount
> End If
> End With
I don't know for sure, but I think you would be better off explicitly
declaring an Excel Application object variable, setting that variable to a
New Excel.Application, and qualifying all Excel method calls from there.
E.g.,
'------ start of revised code ------
Dim objXL As Excel.Application
Dim wbresults As Excel.Workbook
Dim strFile As String
Set objXL = New Excel.Application
With Application.FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\ga1790-1\Desktop\Holder"
.Filename = "R2.xls"
If .Execute > 0 Then
For lCount = 1 To .FoundFiles.Count
strFile = :=.FoundFiles(lCount)
Set wbresults =
objXL.Workbooks.Open(Filename:=.strFile, UpdateLinks:=0)
Killer = Mid(strFile, InStrRev(strFile, "\")
set wbresults = Nothing
Workbooks(Killer).Close False
Kill strFile
Next lCount
End If
End With
objXL.Close
'------ end of revised code ------
However, I can't say I understand the point of this code, so I hope you left
a lot out for brevity.
--
Dirk Goldgar, MS Access MVP
Access tips:
www.datagnostics.com/tips.html
(please reply to the newsgroup)