Excel 从文件夹导入所有工作簿(VBA-Mac)

Excel 从文件夹导入所有工作簿(VBA-Mac),excel,vba,macos,Excel,Vba,Macos,我想将此文件夹中的所有工作簿导入活动工作表。(路径在代码中) 到目前为止,我的代码是: Option Explicit Sub load_all_from_folder() Dim idx As Integer Dim fpath As String Dim fname As String idx = 0 fpath = "/Users/charliekeegan/Desktop/Tester1/" fname = Dir(fpath & "*.csv") While (Len(f

我想将此文件夹中的所有工作簿导入活动工作表。(路径在代码中)

到目前为止,我的代码是:

Option Explicit


Sub load_all_from_folder()
Dim idx As Integer
Dim fpath As String
Dim fname As String

idx = 0
fpath = "/Users/charliekeegan/Desktop/Tester1/"
fname = Dir(fpath & "*.csv")
While (Len(fname) > 0)
    idx = idx + 1
    Sheets("Sheet" & idx).Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
      & fpath & fname, Destination:=Range("A1"))
        .Name = "a" & idx
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileOtherDelimiter = "|"
        .TextFileColumnDataTypes = Array(1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
        fname = Dir
    End With
Wend
End Sub
宏运行,但在我的活动工作表中什么也没有发生-你能看到问题吗


您还知道如何在上传工作表后删除所有工作表吗?

将所有工作簿导入到单个工作表中?你能再解释一下吗?您的意思是将这些csv文件中的所有工作表合并到activeworkbook中吗?一张纸?所有表单都是分开的吗?这是
fpath
值对吗?没有驱动器号<代码>/而不是“\`”?除此之外,该代码对我有效。那么这可能与mac上即时消息返回的代码相同吗?或者看看这些代码,这样就没有驱动器了,我尝试使用/和\但运气不佳。合并.csv代码非常复杂@QHarr,所以我不想使用它。mac bit和Excel版本是你问题中需要提到的一个重要项目!