[VBA ]排序有效日期問題

看板Visual_Basic作者 (low key)時間11年前 (2013/04/04 15:18), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
大家好! 小妹我在自學Excel Vba, 最近練習到把資料夾內的檔案依照檔案時間利用Bubble sort排序後, 再rename成---001 002 003 004 ....以此類推 我先將File_name和File_date利用陣列先抓出來後, 接著利用bubble sort 排序 File_date 目前遇到一個問題, 因為希望程式能抓取較多檔案, 所以我將陣列設成1~100, 又不希望在排序時,程式讀取無效日期, 於是我就寫了下面那一行... If File_date_array(i) <> "" Then 當然是一直出現偵錯>< 請問各位大大如何可以解決這個問題呢? 謝謝!!! 附上現在的進度, Sub bubble_sort_Filedatetime() Dim File_name_array(1 To 100) As String Dim File_date_array(1 To 100) As Date Dim Folder_Path As String Dim strtemp As String Dim i As Long Dim x As String Dim a As Long Dim b As Long Folder_Path = GetFolder("*") '要目錄 If Folder_Path = "" Then Exit Sub Else Folder_Path = Folder_Path & "\" End If i = 0 strtemp = Dir(Folder_Path) 'Workbooks.Add Do While strtemp <> vbNullString If strtemp <> ".." And strtemp <> "." Then i = i + 1 File_name_array(i) = strtemp End If strtemp = Folder_Path & File_name_array(i) 'File_date_array(i) = CDate(FileDateTime(strtemp)) strtemp = Dir Loop If File_date_array(i) <> "" Then For i = 1 To 100 For b = 2 TO 100 a = b - 1 If File_date_array(a) < File_date_array(b) Then File_date_array(a) = x File_date_array(a) = File_date_array(b) x = File_date_array(b) End If Next b Next i -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.163.80.113

04/05 23:16, , 1F
IsDate
04/05 23:16, 1F
文章代碼(AID): #1HNIafBN (Visual_Basic)