Dim Ex As Excel.Application
Dim Wb As Excel.Workbook
Dim Sh As Excel.Worksheet
Dim rs As ADODB.Recordset
Dim s As String
Dim c As Integer
Dim iLineCount As Integer
Dim fld,r,val
Set Ex = New Excel.Application
Ex.Visible = False
Set Wb = Ex.Workbooks.Add(sFileName)
s = "pl_logo,pl_time,pl_name,pl_timing,..."
fld = Split(s, ",")
For Each Sh In Wb.Worksheets
Set rs = New ADODB.Recordset
rs.Open "select * from ut_playlist", CurrentProject.Connection, 1, 3, 8
iLineCount = 2
Do
'Бежим по строкам
s = Sh.Cells(iLineCount, 1)
If Len(s) = 0 Then Exit Do
'Бежим по колонкам
For c = 2 To 12
val = Sh.Cells(iLineCount, c)
If c = 3 Then
s = Format(val, "00\:00\:00\:00")
Else
s = Trim("" & val)
End If
r(c - 1) = s
Next
rs.AddNew
For i = 0 To iFieldCount - 1
On Error Resume Next
If Len(r(i)) = 0 Then
rs.Fields(fld(i)).Value = Null
Else
Dim fd As ADODB.Field
Set fd = rs.Fields(fld(i))
If fd.Type = adVarChar Then
fd.Value = Left("" & r(i), fd.DefinedSize)
Else
fd.Value = "" & r(i)
End If
End If
Next
rs.Update
iLineCount = iLineCount + 1
Loop
rs.Close
Set rs = Nothing
Next
Ex.Quit
Set Ex = Nothing
|