当我“进入”代码并将每个文件中的数据粘贴到“思科数据库”文件中时,下面的代码效果很好。但是,当我运行它时,它总是会忽略最后一个文件。我每次都添加了一个特定的行来保存数据库文件,但无济于事。有什么建议么?
Sub AppendDataFinal()
Dim myWorkbook As String
myDB = "CiscoDatabase.xlsx"
myWorkbook = "Cisco.xlsm"
Application.Run "'Cisco.xlsm'!importfile" //grabs all .csv files from a folder
For Each wb In Workbooks
If (wb.Name <> myWorkbook) Then wb.Activate
Columns("A:O").Select
Selection.Delete Shift:=xlUp
Columns("O:AS").Select
Selection.Delete Shift:=xlUp
Selection.CurrentRegion.Select
Selection.Copy
Workbooks.Open ("file path")
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste , False
Range("A1").Select
If (ActiveWorkbook.Name = myDB) Then ActiveWorkbook.Save
ActiveWorkbook.Close
ActiveWorkbook.Close savechanges:=False
Next wb
Workbooks.Open ("file path and name")
Application.Run "Cisco.xlsm!DateFormat" //trims time off date row, pretties up data
End Sub