- 帖子
- 559
- 主題
- 58
- 精華
- 0
- 積分
- 626
- 點名
- 0
- 作業系統
- win8
- 軟體版本
- office2013
- 閱讀權限
- 50
- 性別
- 男
- 來自
- TW
- 註冊時間
- 2010-11-22
- 最後登錄
- 2024-6-14
|
5#
發表於 2012-7-9 17:30
| 只看該作者
本帖最後由 hugh0620 於 2012-7-9 17:31 編輯
回復 4# qwern
試試下面的寫法~ 依你上載的資料還撰寫~ 將資料夾中的EXCEL檔匯在同一個sheet中~
A3="檔案名稱"
B3=欄位A
A3&B3是要有欄位名稱唷- Application.Calculation = xlCalculationManual
- Dim Ar()
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show = 0 Then Exit Sub ' 若是沒有選取資料夾路徑,就跳出程序
- Sheet1.Rows("4:1048576").ClearContents
- fd = .SelectedItems(1)
- If .ButtonName = "確定" Then
- fs = Dir(fd & "\*.xls")
- Do Until fs = ""
- fds = fd & "\" & fs
- With Workbooks.Open(fds)
- A = .Sheets(1).Range("A65536").End(xlUp).Row
- BN = .Sheets(1).Name
- .Sheets(1).Range("A1:CW" & A).Copy Sheet1.Range("B1048576").End(xlUp).Offset(1, 0)
- .Close 0
- End With
- C1 = Sheet1.Range("A1048576").End(xlUp).Offset(1, 0).Row
- C2 = Sheet1.Range("B1048576").End(xlUp).Row
- Sheet1.Range("A" & C1 & ":A" & C2) = BN
- fs = Dir
- Loop
- End If
- End With
- Application.Calculation = xlCalculationAutomatic
複製代碼 |
|