Filesearch in Remotely Called Macro

G

Guest

Hello,
I'm using WSH to call a vbs script on a remote machine that launches Excel
and calls a stored macro. The script successfully launches and the macro is
successfully run.

However, within this macro, I use FileSearch to query a directory on a
shared file sever. When I run the vbs script locally, the FileSearch
executes correctly and FileSearch returns all files in the directory.
However, when I launch the script remotely, .Execute returns 0 and the macro
is done. In both cases, the Dir method returns that the path is valid, so it
doesn't seem to be an issue with visibility to the directory or server. I've
pasted the macro code below.

Any ideas why FileSearch wouldn't execute in a macro that is called remotely?

Many Thanks! Pat



Public Sub TestMacro()
' LogInformation is a call to a sub that logs to a text file

On Error Resume Next


Const workingDir As String = "\\servername\path\to\directory\"

If Dir(workingDir, vbDirectory) <> "" Then
LogInformation ("Path is VALID")
Else
LogInformation ("Path is NOT VALID")
End If


' Search for xls files within workingDir
With Application.FileSearch
.NewSearch
.LookIn = workingDir
.SearchSubFolders = False
.fileName = "*.*"

LogInformation ("Found Files?")

'If you find files, do what we came here for
If .Execute() > 0 Then

LogInformation ("Found Files: True")

For i = 1 To .FoundFiles.Count

LogInformation ("File " & i & ": " & .FoundFiles(i))

Next i

Else
LogInformation ("Found Files: False")
End If

End With

End Sub
 

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

Similar Threads


Top