Sub test()
ThisWorkbook.Sheets("Format TXT").Range("A1").CurrentRegion.Copy 'LLe fichier Schema.ini contient le format du fichier tex à créer {voire onglet Format TXT}!
CreerTxt ThisWorkbook.Path & "\Schema.ini", Replace(PressePapier, vbTab, " ")
CreerTxt ThisWorkbook.Path & "\TEST.CSV", ""
With CreateObject("Adodb.connection") 'Fichier vierge !
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & ";Extended Properties=""Text;HDR=No;FMT=FixedLength;"""
.Execute "insert into [TEST#CSV] select * from [Donnees$] in '" & ThisWorkbook.FullName & "' 'excel 12.0;HDR=no;IMEX=1;'"
.Close
End With
End Sub
Private Sub CreerTxt(Fichier, TxtDefault As String) 'Ici on génère un fichier text
Dim FSO, NewFichier
Set FSO = CreateObject("Scripting.FileSystemObject")
Set NewFichier = FSO.OpenTextFile(Fichier, 2, True)
NewFichier.Write TxtDefault
NewFichier.Close
Set NewFichier = Nothing
Set FSO = Nothing
End Sub
Public Property Let PressePapier(Value) 'Ici place un texte dans le press papier
Const DATAOBJECT_BINDING As String = "new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"
With CreateObject(DATAOBJECT_BINDING)
.SetText Value
.PutInClipboard
End With
End Property
Public Property Get PressePapier() 'Ici on récupère le texte du press papier
Const DATAOBJECT_BINDING As String = "new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"
With CreateObject(DATAOBJECT_BINDING)
.GetFromClipboard
PressePapier = .GetText
End With
End Property