返回列表 上一主題 發帖

[發問] getFolder如何取得到第二層資料夾

[發問] getFolder如何取得到第二層資料夾

我想請問高手們,目前以下程式碼只能做到讀取一層資料夾的讀取而已,請問哪裡寫錯了嘛
我想要可以讀取我選擇好的目錄下所有的資料夾,可是不知道哪裡寫錯了
已經爬文許久,但始終無法找到答案,請高手們指點迷津,感恩
  1. Set oexcel = CreateObject("Excel.Application")
  2.     Dim objF As Object  '定義開檔物件
  3.     Dim strFoldersName As String    '定義資料夾名稱為字串型態
  4.     Dim strAllName As String   '定義所有名稱
  5.     'Dim objFs2 As Scripting.FileSystemObject
  6.    
  7.     Dim fObj2, fc2
  8.     Dim objF2 As Object
  9.    
  10.    
  11.     Dim strFolderPath As String
  12.     Dim strGetFilePath As String
  13.     strGetFilePath = File1.Path
  14.    
  15.     strFolder = Text1.Text
  16.    
  17.     Set gobjFs = CreateObject("Scripting.FileSystemObject")
  18.     Set objF = gobjFs.GetFolder(strGetFilePath)
  19.     Set fc = objF.SubFolders
  20.    
  21.     For Each F1 In fc
  22.         
  23.      
  24. 'Set oexcel = CreateObject("Excel.Application")

  25. MyPath = F1


  26. i = 0


  27. MyFile = Dir(MyPath & "\*_1.csv")  '要開啟的資料檔名


  28.                            
  29. 'g = Mid(MyFile, 1, 18)

  30.     Do While Len(MyFile) > 0
  31.    
  32.    
  33.    
  34.     Call class_NT
  35.     Application.DisplayAlerts = False  ' 關閉警告訊息
  36.    
  37.     Application.DisplayAlerts = True   ' 再打開警告訊息
  38.     i = i + 1
  39.     MyFile = Dir                                                     '下一筆
  40.     Loop
  41.     Next
複製代碼

回復 1# z15935712

搜尋一下 資料夾
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

剛剛爬完GEKEE 大大的文章
請問搜尋目標資料夾中底下的所有子資料夾是哪一段?
能幫我加上註解嗎,謝謝

TOP

請問搜尋目標資料夾中底下的所有子資料夾是哪一段?
coblo 發表於 2014/9/4 17:46




如圖 逐步執行,到VBA視窗按 F8 可慢慢膫解.
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 不要小看自己,因為人有無限的可能。
返回列表 上一主題