I'd do this with one workbook in which the files to process are listed in a sheet, lets say Sheet1 in Column A. So the driving code might be something like :
Code:
Foreach MyCell in worksheets("Sheet1").Range("A1:A100")
call ReadWkBk( MyCell.Value )
next (or you might scan files for xls in a directory etc)
To load the workbooks and squirt the data at the database (ooerr missus) :
Code:
sub ReadWkBk( sFile as string )
Dim sServer, sDBName As String
sServer = "TheServer"
sDBName = "TheDatabase"
Dim ConnectionString As String
ConnectionString = _
"Provider=SQLOLEDB;" & _
"Data Source=" + sServer + ";" & _
"Initial Catalog=" + sDBName + ";" & _
"Integrated Security=SSPI"
' Connection assumes you have permission to connect to the named database as part of an AD
' group. Early binding assumes you have references set to the appropriate active X lib
Set connection = CreateObject("ADODB.Connection")
connection.Open ConnectionString
dim wbIn as Workbook
Set wbIn = Workbooks.Open(sFile)
dim rSheet as Range
Set rSheet = wbIn.Worksheets("Sheet1").Range("A1:AZ10000")
Dim iRow as integer
iRow = 1
Dim sSQL as string
' Process rows while there is a value in the first column
While rSheet(iRow,1).value <> ""
' Build a SQL command
sSQL = "INSERT INTO <table> (Field1,Field2,Field3 ... etc) VALUES ( " +_
rSheet(iRow,1).value + "," + _
rSheet(iRow,2).value + "," + _
rSheet(iRow,3).value + "," + _
... etc + _
" )"
' Excecute the SQL
Set Recordset = connection.Execute(sSQL, recs, CommandTypeEnum.adCmdText)
' Move to next row
iRow = iRow + 1
wend
connection.close
wbIn.Close
end sub Or summat very much like that.