回覆列表
  • 1 # 使用者4412593244664

    同時按alt+f11這二個鍵,進入vba編輯介面,點選編輯畫面的選單:“插入”--“模組”,然後在裡面完整複製下面的程式碼:<br><br>sub 同一資料夾多xls合併()<br>"sub mergeonexls() "合併多工作簿中指定工作表<br>on error resume next<br>dim x as variant, x1 as variant, w as workbook, wsh as worksheet<br>dim t as workbook, ts as worksheet, l as integer, h as long<br>application.screenupdating = false<br>application.displayalerts = false<br>x = application.getopenfilename(filefilter:="excel檔案 (*.xls; *.xlsx),*.xls; *.xlsx,所有檔案(*.*),*.*", _<br> title:="excel選擇", multiselect:=true)<br>set t = thisworkbook<br>set ts = t.sheets(1) "指定合併到的工作表,這裡是第一張工作表<br>l = ts.usedrange.specialcells(xlcelltypelastcell).column<br>for each x1 in x<br>if x1 <> false then<br> set w = workbooks.open(x1)<br> set wsh = w.sheets(1) "指定所需合併工作表,這裡是第一張工作表<br> h = ts.usedrange.specialcells(xlcelltypelastcell).row<br> if l = 1 and h = 1 and ts.cells(1, 1) = "" then<br> wsh.usedrange.copy ts.cells(1, 1)<br> else<br> wsh.usedrange.copy ts.cells(h + 1, 1)<br> end if<br> w.close<br>end if<br>next<br>application.screenupdating = true<br>application.displayalerts = true<br>end sub<br><br>接著繼續在編輯畫面避點選選單:工具--宏,選擇“同一資料夾多xls合併”--點執行,開始選擇你想合併的工作簿,請用滑鼠多個點選選取

  • 中秋節和大豐收的關聯?
  • pB0在蘋果樹和桃樹上具體怎樣應用,效果如何?