早上好,这是我在这里发表的第一篇文章......所以请耐心等待我:)
我正在尝试在Excel 2016上执行的VBA代码出现问题。我正在运行MacOSX Sierra计算机。
每天我需要从3个.csv文件中导入数据并将其放在3个不同的Excel工作表上,以特定方式格式化数据并添加网页链接,所以我在excel文件上录制了一个宏来为我做这个。< / p>
以下是导入单个.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
任何建议都将不胜感激。 谢谢!