亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Dir()函數在Mac Excel 2011 VBA中不起作用

Dir()函數在Mac Excel 2011 VBA中不起作用

婷婷同學_ 2019-12-04 11:06:04
嗨,我正在嘗試列出Excel工作簿所在子目錄中的所有文件。由于某些原因,該代碼無法執行Dir功能。任何人都可以請教嗎?謝謝!Sub ListFiles()    ActiveSheet.Name = "temp"    Dim MyDir As String    'Declare the variables    Dim strPath As String    Dim strFile As String    Dim r As Long    MyDir = ActiveWorkbook.Path 'current path where workbook is    strPath = MyDir & ":Current:" 'files within "Current" folder subdir, I am using Mac Excel 2011    'Insert the headers in Columns A, B, and C    Cells(1, "A").Value = "FileName"    Cells(1, "B").Value = "Size"    Cells(1, "C").Value = "Date/Time"    'Find the next available row    r = Cells(Rows.Count, "A").End(xlUp).Row + 1    'Get the first file from the folder            'Note: macro stops working here    strFile = Dir(strPath & "*.csv", vbNormal)    'Loop through each file in the folder    Do While Len(strFile) > 0        'List the name, size, and date/time of the current file        Cells(r, 1).Value = strFile        Cells(r, 2).Value = FileLen(strPath & strFile)        Cells(r, 3).Value = FileDateTime(strPath & strFile)        'Determine the next row        r = r + 1        'Get the next file from the folder        strFile = Dir    Loop    'Change the width of the columns to achieve the best fit    Columns.AutoFitEnd Sub
查看完整描述

3 回答

?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

對于上面的答案,當我在MacID中取出“ TEXT”時,它對我有用:


Sub LoopThruFiles()


    Dim mydir As String

    Dim foldercount As Integer

    Dim Subjectnum As String

    Dim strpath As String

    Dim strfile As String


    ChDir "HD:Main Folder:"

    mydir = "HD:Main Folder:"

    SecondaryFolder = "Folder 01:"

    strpath = mydir & SecondaryFolder


    strfile = Dir(strpath)


    'Loop through each file in the folder

    Do While Len(strfile) > 0

     If Right(strfile, 3) = "cef" Then

        MsgBox (strfile)

        End If

        strfile = Dir

    Loop

End Sub


查看完整回答
反對 回復 2019-12-04
  • 3 回答
  • 0 關注
  • 870 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號