返回列表 上一主題 發帖

[發問] 從某資料夾中,將檔案名稱建立在excel中

回復 2# hugh0620
試試看
  1. Option Explicit
  2. Private Sub CommandButton1_Click()
  3. Dim myPath As String
  4. Dim K As Integer
  5. Dim F As Object, E As Object
  6. With Application.FileDialog(msoFileDialogFolderPicker)
  7.     'If .ButtonName = "確定" Then
  8.     '**不管你是否按下確定鍵,或是關閉對話視窗, ** 這行程式碼都是正確的 ***'
  9.     If .Show = True Then   '有按下確定鍵
  10.         myPath = .SelectedItems(1)
  11.         Set F = CreateObject("Scripting.FileSystemObject").GetFolder(myPath).Files
  12.         'FileSystemObject 物件 有提供檔案內容的屬性可用
  13.         If F.Count > 0 Then
  14.             Cells.Clear
  15.             K = 5
  16.             Cells(K, "a") = "No"
  17.             Cells(K, "b") = "路徑"
  18.             Cells(K, "c") = "音檔案名稱"
  19.             Cells(K, "d") = "檔案大小"
  20.             Cells(K, "E") = "檔案型態"
  21.             For Each E In F
  22.                 If E.Type = "MP3 格式聲音" Then  '指定你的檔案型態: "影音檔"
  23.                     K = K + 1
  24.                     Cells(K, "a") = K - 5
  25.                     Cells(K, "b") = myPath
  26.                     Cells(K, "c") = E.Name
  27.                     Cells(K, "d") = Format(E.Size / 1024, "#,000 KB")
  28.                     Cells(K, "E") = E.Type
  29.                 End If
  30.             Next
  31.         End If
  32.     End If
  33. End With
  34. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 能善用時間的人,必能掌握自己努力的方向。
返回列表 上一主題