#contents *Excel 関連情報 [#l826ede2] **ADOによるExcelシート連結 [#t47247cf] -マージ前 [E:\home\edu\excel\tmp\data\book1.xls].[Sheet1] Field1 Field2 Field3 ------ ------ ------ aaa 123 AAA bbb 456 BBB ccc 789 CCC [E:\home\edu\excel\tmp\data\book2.xls].[Sheet1] Field1 Field2 Field3 ------ ------ ------ ddd 111 DDD eee 222 EEE fff 333 FFF [E:\home\edu\excel\tmp\data\book3.xls].[Sheet1] Field1 Field2 Field3 ------ ------ ------ ggg 444 GGG hhh 555 HHH iii 666 III [E:\home\edu\excel\tmp\marge.xls].[Sheet1] Field1 Field2 Field3 ------ ------ ------ -マージ後 [E:\home\edu\excel\tmp\marge.xls].[Sheet1] Field1 Field2 Field3 ------ ------ ------ aaa 123 AAA bbb 456 BBB ccc 789 CCC ddd 111 DDD eee 222 EEE fff 333 FFF ggg 444 GGG hhh 555 HHH iii 666 III -ExcelMarge.vbs ' ExcelMarge.vbs ' Usage : CScript ExcelMarge.vbs Const DIR = "E:\home\edu\excel\tmp\data" ' 対象データ Const XLS = "E:\home\edu\excel\tmp\marge.xls" ' マージ先のファイル Marge Sub Marge Dim cn Dim rs Set cn = CreateObject("ADODB.Connection") cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & XLS & ";Extended Properties=Excel 8.0" Dim fs Set fs = CreateObject("Scripting.FileSystemObject") Dim folder Set folder = fs.GetFolder( DIR ) Dim file For Each file In folder.Files cn.Execute "INSERT INTO [Sheet1$] SELECT * FROM [Excel 8.0;database=" & file & "].[Sheet1$]" Next End Sub #ref(http://www.hondarer-soft.com/cx/pukiwiki/pukiwiki.php?plugin=attach&pcmd=open&file=excel_marge.zip&refer=Memo%2F2004-04-26,excel_marge.zip) ■ excel_marge.zip ファイルの詳細 D:\HOME\EDU\EXCEL\EXCEL_MARGE │ macro.vbs … XLSマージスクリプト(VBScriptバージョン) │ macro.xls … XLSマージスクリプト(Excel/VBAバージョン) │ marge.xls … マージ先のファイル │ └─data … マージ対象ファイル aaa.xls bbb.xls ccc.xls -はてな --http://www.hatena.ne.jp/1082980300 #comment //#comment