Function GetFileName()
Dim j As Byte
With Application.FileDialog(msoFileDialogFilePicker)
.Show
j = .SelectedItems.Count
If j > 0 Then GetFileName = .SelectedItems(j)
End With
End Function
Sub CreateShemaIni(PathShema, NameSchema, ColumnSep, _
TextSep, OptionalFields As Boolean)
Dim MyFile
MyFile = FreeFile
Open PathShema & "Schema.ini" For Output As #MyFile
Print #MyFile, "[" & NameSchema & "]"
Print #MyFile, "ColNameHeader=" & IIf(OptionalFields, "TRUE", "FALSE")
Print #MyFile, "Format=" & ColumnSep
Print #MyFile, "TextDelimiter=" & TextSep
Close #MyFile
End Sub
Sub test()
Dim sCon$, PathBase$, FulFilename$, FileNameTXT$, File_PathTXT$, Sql$
Dim cn As Object, tmp
PathBase = GetFileName '"Ваш путь к файлу access"
FulFilename = GetFileName ''"Ваш путь к файлу импорта"
Set cn = CreateObject("ADODB.Connection")
tmp = Split(FulFilename, Application.PathSeparator)
FileNameTXT = tmp(UBound(tmp))
File_PathTXT = Replace(FulFilename, FileNameTXT, "")
CreateShemaIni File_PathTXT, FileNameTXT, "Delimited(;)", "", False
'[PFONE]-таблица куда импортируем
'NUMPASPORT,NAMEKLIENT,PFONE - наименование полей куда импортируем
Sql = "Insert into [PFONE]" _
& " Select F1 as NUMPASPORT,F2 as NAMEKLIENT, F3 as PFONE" _
& " From [" & FileNameTXT _
& "] IN '" & File_PathTXT & "'" & "[Text;]"
cn.ConnectionString = "Provider= Microsoft.Jet.OLEDB.4.0;Data Source=" & PathBase
cn.Open
cn.Execute Sql
cn.Close
End Sub |