运行时错误1004上.Refresh BackgroundQuery:= False VBA

早安,那是我的第一篇文章…所以请耐心等待:)

我有一个VBA代码的问题,我试图在Excel 2016上执行。我正在运行一台MacOSX Sierra机器。

每天我需要从3个.csv文件导入数据,并把它放在3个不同的Excel工作表,以特定的方式格式化数据,并添加一个networking链接,所以我logging了一个macros的Excel文件,这对我来说。

这里是导入一个.csv的代码(对于所有的都是一样的)

Sub csvimport() ' ' csvimport Macro ' ' Keyboard Shortcut: Option+Cmd+Shift+I ' Sheets("displayAddedByCollaboration").Select Columns("A:A").Select With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;/Users/oem/Desktop/report/displayAddedByCollaborationReport.csv", _ Destination:=Range("A1")) .Name = "displayAddedByCollaborationReport" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .TextFilePromptOnRefresh = False .TextFilePlatform = xlMacintosh .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1) .Refresh BackgroundQuery:=False .UseListObject = False End With ActiveWindow.ScrollColumn = 16 Range("U2").Select ActiveCell.FormulaR1C1 = _ "=IF(RC[-3] = """","""",HYPERLINK(""https://www.google.it/"",""View receipt""))" Range("U2").Select Selection.AutoFill Destination:=Range("U2:U2001"), Type:=xlFillDefault Range("U2:U2001").Select ActiveWindow.ScrollRow = 1 ActiveWindow.ScrollColumn = 1 Cells.Select Selection.AutoFilter ActiveWorkbook.Worksheets("displayAddedByCollaboration").AutoFilter.Sort. _ SortFields.Clear ActiveWorkbook.Worksheets("displayAddedByCollaboration").AutoFilter.Sort. _ SortFields.Add Key:=Range("A1:A2001"), SortOn:=xlSortOnValues, Order:= _ xlDescending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("displayAddedByCollaboration").AutoFilter.Sort .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub 

它工作好几天,并意外地,它停止工作返回运行时错误1004.代码停在这一行,我不明白为什么:

 .Refresh BackgroundQuery:=False 

这是我的桌面上的报告文件夹的内容:

 Mauros-MacBook-Pro-2:~ oem$ cd /Users/oem/Desktop/report/ Mauros-MacBook-Pro-2:report oem$ ls -la total 2592 drwx------@ 6 oem staff 204 May 5 08:35 . drwx------+ 12 oem staff 408 May 5 09:53 .. -rw-r--r--@ 1 oem staff 6148 May 5 08:35 .DS_Store -rwxr-xr-x@ 1 oem staff 46795 May 5 08:32 displayAddedByCollaborationReport.csv -rwxr-xr-x@ 1 oem staff 55837 May 5 08:32 eanNotInAnagraphic.csv -rwxr-xr-x@ 1 oem staff 1210072 May 5 08:32 notCertifiedProductRecognizedReport.csv 

任何build议,将不胜感激。 谢谢!