VBA 合併多個工作簿

2022-07-28 10:06:24 字數 1532 閱讀 1488

'

合併多個工作薄,並以工作薄的名字給sheet表命名(每個工作薄只有一張表)

subtest()

dimstr

asstring

dim wb as

workbook

str = dir("

c:\users\administrator\desktop\6.3_6.7\*.xls*")

for i = 1

to100

set wb = workbooks.open("

c:\users\administrator\desktop\6.3_6.7\

" & str

)

'檔案彙總

wb.sheets(1).copy after:=thisworkbook.sheets(thisworkbook.sheets.count)

'使用檔名命名sheet表名,帶檔案字尾名。

'thisworkbook.sheets(thisworkbook.sheets.count).name = wb.name

'使用split分隔,實現去掉字尾

thisworkbook.sheets(thisworkbook.sheets.count).name = split(wb.name, "

.")(0

)

wb.close

str = dir

ifstr = ""

then

exit

forend

ifnext

end sub

'

乙個工作簿有多個sheet表,以sheet表的名字命名

subtest()

dimstr

asstring

dim wb as

workbook

dim sht as

worksheet

str = dir("

e:\data\*.xls*")

for i = 1

to100

set wb = workbooks.open("

e:\data\

" & str

)

'檔案彙總

foreach sht in

wb.sheets

sht.copy after:=thisworkbook.sheets(thisworkbook.sheets.count)

'thisworkbook.sheets(thisworkbook.sheets.count).name = split(wb.name, ".")(0) & sht.name

thisworkbook.sheets(thisworkbook.sheets.count).name =sht.name

next

wb.close

str = dir

ifstr = ""

then

exit

forend

ifnext

end sub

使用VBA合併多個Excel工作簿

有許多實現excel工作簿合併的方法,在 將多個工作簿中的資料合併到乙個工作簿 中介紹過合併工作簿的示例。下面再列舉幾個示例,供有興趣的朋友參考。例如,需要將多個excel工作簿中的工作表合併到乙個工作簿。這裡假設需要合併的工作簿在 d 示例 資料記錄 資料夾中,含有兩個工作簿test1.xls t...

合併多個excel工作簿

合併多個excel工作簿,會出現 號碼以科學計數法顯示,如果想要以字串方式處理,要按如下完整 public static void mergeworkbook throws exception hssfsheet sheetcreat wbcreat.createsheet bookname she...

多個excel工作簿 工作表合併

功能描述 合併當前資料夾下面所有excel,包括每乙個工作簿與每乙個工作簿下面的每乙個工作表 步驟 1 所有表的每個sheet需要表頭一致 2 所有表需要放在乙個資料夾下面 3 該程式會合併當前資料夾下面所有字尾名為指定字尾名的資料 4 在該資料夾下面新建乙個同樣字尾名的excel 5 開啟新建的 ...