Error: The remote server machine does not exist or is unavailable

A

Amanda

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
 
D

Dirk Goldgar

Amanda said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top