P
Pat at ACS
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
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