最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

excel - Automation error - An unexpected network error occurred - Stack Overflow

programmeradmin3浏览0评论

The above error is encountered when trying to loop through sub-folders on a mapped network drive.

The function works as expected when applied to the local C:\ DRIVE.

Any ideas how I can overcome this problem?

The error occurrs on the following line: For Each subfolder In folder.SubFolders

Function FindFolder(ByVal strStartFolder As String, ByVal strFolderNamePattern As String) As String

  Dim fso As Object, folder As Object, subfolder As Object

  Set fso = CreateObject("Scripting.FileSystemObject")

  On Error Resume Next 

  Set folder = fso.GetFolder(strStartFolder)

  On Error GoTo 0

  If folder Is Nothing Then
    FindFolder = "" 
    Exit Function
  End If


  'Check the current folder first
  If FolderMatchesPattern(folder.Name, strFolderNamePattern) Then
    FindFolder = folder.Path
    Exit Function
  End If

  'Recursively search subfolders
  For Each subfolder In folder.SubFolders
    FindFolder = FindFolder(subfolder.Path, strFolderNamePattern) 
    If FindFolder <> "" Then 
      Exit Function
    End If
  Next subfolder

  FindFolder = "" 
  Set fso = Nothing 
  Set folder = Nothing
  Set subfolder = Nothing

End Function
发布评论

评论列表(0)

  1. 暂无评论