ChDrive "C"
ChDir "C:\"
NewName = "TEST.prn" '
nmFichier = "TEST"
nmFichierSauvé = Application.GetSaveAsFilename(nmFichier, _
"Texte (séparateur: espace) (*.prn), *.prn", , _
"Export de fichiers texte")
idFichier = FreeFile()
Open nmFichierSauvé For Output As #idFichier
nbLignes = Selection.Rows.Count
nbColonnes = Selection.Columns.Count
For iLigne = 1 To nbLignes
For iColonne = 1 To nbColonnes
With Selection.Cells(iLigne, iColonne)
largCellule = Application.Round(.ColumnWidth, 0)
txtCellule = .Text
If Len(txtCellule) < largCellule Then
Select Case .HorizontalAlignment
Case xlGeneral, xlFill
If Application.IsNumber(.Value) Then
txtCellule = String(largCellule - Len(txtCellule), " ") & txtCellule
Else
txtCellule = txtCellule & _
String(largCellule - Len(txtCellule), " ")
End If
Case xlLeft, xlJustify
txtCellule = txtCellule & _
String(largCellule - Len(txtCellule), " ")
End Select
Else
txtCellule = Left(txtCellule, largCellule)
End If
End With
Print #idFichier, txtCellule;
Next iColonne
If iLigne <> nbLignes Then Print #idFichier, ""
Next iLigne
Close #idFichier
On Error Resume Next
Kill "C:\TEST.txt"
Name "C:\TEST.prn" As "C:\TEST.txt"