返回列表 上一主題 發帖

[發問] VBA 開啟多個檔案 複製貼上

回復 4# character
  1. Sub 加入檔案()
  2. fds = Application.GetOpenFilename("Excel Files (*.xls;*.xlsx), *.xls;*.xlsx", , , , True)
  3. If IsArray(fds) Then
  4. For i = 1 To UBound(fds)
  5.    [A1].Offset(i - 1) = fds(i)
  6. Next
  7. End If
  8. End Sub
  9. Sub 執行()
  10. For Each a In Range([A1], Cells(Rows.Count, 1).End(xlUp))
  11.   With Workbooks.Open(a)
  12.      .Sheets(1).[A1:C6].Copy ThisWorkbook.Sheets("Result").Cells(Rows.Count, 1).End(xlUp).Offset(1)
  13.      .Close 0
  14.   End With
  15. Next
  16. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 能幹不幹,不如苦幹實幹。
返回列表 上一主題