ник: час
Public Function Fun_TABLE_IN_XLS(STR_TABLE_NAME As String, To_ROTIN As Boolean, TO_MESSING As Boolean)
' ïåðåáðîñ òàáëèöû â ôàéë Excel
' To_Rotin = true - ïîêàçàòü(îòêðûòü) ôàéë
' To_Message = true - ñîîáùèòü î ïåðåáðîñå
If FUN_Vopros("Âûãðóæàåì â ôàéë Excel? ", vbQuestion) = False Then Exit Function
Dim FILE_STROKA As String ' Ôîðìèðóåìàÿ ñòðîêà
Dim lngPID As Variant ' ïðîñòî ïåðåìåííàÿ
Dim FILE_NAME As String ' èìÿ ôàéëà
Dim FIEL As ADODB.Field ' ïîëå
Dim FIEL1 As ADODB.Field ' ïîëå
Dim rst2 As ADODB.Recordset ' íàáîð çàïèñåé
Set rst2 = New ADODB.Recordset ' íàáîð çàïèñåé
Dim ConnectionString As String ' Ñîåäèíåíèå
Dim ExcelConnection As New ADODB.Connection ' Ñîåäèíåíèå
Dim SQLCommand As String ' Ôîðìèðóåìàÿ ñòðîêà êîìàíä
Dim Cmd As New ADODB.Command ' êîìàíäà
GLB_Patch_REPORT = FUN_OUT_TABLE_String("TUNING_TBL", "Patch", "Ïàïêà_Îò÷åòîâ", "ID")
FILE_NAME = FUN_FILE_NAME_IN(STR_TABLE_NAME, "xls")
FILE_NAME = FUN_Patch_File(GLB_Patch_REPORT, FILE_NAME)
If FUN_FILE_YES_NO(FILE_NAME) = True Then FUN_Delete_File_Name (FILE_NAME)
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Excelåtest.xls;Extended Properties=Excel 8.0"
ExcelConnection.Open ConnectionString
rst2.Open "SELECT " & STR_TABLE_NAME & ".* FROM " & STR_TABLE_NAME & " WITH OWNERACCESS OPTION;", GLB_con, adOpenKeyset, adLockOptimistic
If rst2.EOF = False Then ' åñëè òàáëèöà (rst2) íå ïóñòà ïåðåíîñ
FILE_STROKA = ""
' íàçâàíèÿ ñòîëáöîâ (çàãîëîâêè)
For Each FIEL In rst2.Fields
FILE_STROKA = FILE_STROKA & "[" & FIEL.Name & "] TEXT(150), "
Next FIEL
FILE_STROKA = Mid(FILE_STROKA, 1, Len(FILE_STROKA) - 2)
SQLCommand = "CREATE TABLE sheet1 (" & FILE_STROKA & ")"
Cmd.ActiveConnection = ExcelConnection
Cmd.CommandText = SQLCommand
Cmd.Execute
For Each FIEL1 In rst2.Fields 'çíà÷åíèÿ
SQLCommand = "INSERT INTO sheet1." & FIEL1.Name & " VALUES (" & FIEL1 & ")"
Cmd.ActiveConnection = ExcelConnection
Cmd.CommandText = SQLCommand
Cmd.Execute
FILE_STROKA = ""
Next FIEL1
End If
rst2.Close
Set rst2 = Nothing
ExcelConnection.Close
Set ExcelConnection = Nothing