Board logo

標題: [發問] 計算資料夾內xls檔案數 [打印本頁]

作者: acdx    時間: 2014-12-26 14:38     標題: 計算資料夾內xls檔案數

該如何計算資料夾內.xls檔案數?
mypath = ActiveWorkbook.Path & "\"
myFile = "*.xls"
myname = Dir(mypath & myFile)
n = myname.Count

結果最後一行出現錯誤
該怎麼修正?
作者: GBKEE    時間: 2014-12-26 15:25

回復 1# acdx
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim mypath As String, myFile As String, myname As String, n As Integer
  4.     mypath = ActiveWorkbook.Path & "\"
  5.     myFile = "*.xls"
  6.     myname = Dir(mypath & myFile)
  7.     Do While myname <> ""
  8.         n = n + 1
  9.         myname = Dir
  10.     Loop
  11.     MsgBox n
  12. End Sub
複製代碼





歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)