Sub RTF_Vers_XL3()
'ajouter la référence dans VBE à Microsoft Word Library
Dim wApp As Word.Application
Dim oDoc As Word.Document
Dim wdFileName, txtFile$
Set wApp = New Word.Application
wdFileName = Application.GetOpenFilename("Format RTF, *.rtf")
txtFile = Replace(wdFileName, "rtf", "txt")
If wdFileName = False Then Exit Sub
'conversion du *.RTF en *.txt
Set oDoc = wApp.Documents.Open(wdFileName)
oDoc.SaveAs2 Filename:=txtFile, FileFormat:=wdFormatText, Encoding:=1252, InsertLineBreaks:=True, LineEnding:=wdCRLF
oDoc.Close SaveChanges:=wdDoNotSaveChanges
wApp.Quit
Set wApp = Nothing
'Ouverture du *.txt dans Excel
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & txtFile, Destination:=Range("$A$1"))
.Name = "test3"
.FieldNames = True: .PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells: .SaveData = True
.AdjustColumnWidth = True: .RefreshPeriod = 0
.TextFilePlatform = 1252: .TextFileStartRow = 1: .TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileColumnDataTypes = Array(1): .Refresh BackgroundQuery:=False
End With
End Sub