Macro pour faire une exportation .txt d'une sélection précise

Bonjour,

J'essaie de réaliser une exportation d'une sélection d'une de mes 5 feuilles excel mais mon code ne fonctionne pas...

Sub export_txt()

Dim wb As Workbook
Dim ws As Worksheet
Dim newWB As Workbook
Dim newWS As Worksheet
Dim Nom_Sauvegarde As String

Application.ScreenUpdating = False

Set wb = ActiveWorkbook
Set ws = ActiveSheet

Range("$A$1:$R$20").Select

With Selection
        .Copy
End With

Set newWB = ActiveWorkbook

Nom_Sauvegarde = InputBox("Entrer le nouveau nom de fichier :")

With newWB
        .SaveAs Nom_Sauvegarde, xlText
        .Close (False)
End With

    wb.Activate

exitSave:
    Application.ScreenUpdating = True
    Exit Sub

End Sub

Voici ce que j'ai fait.

Bonjour,

essayer ce code

Sub export_txt()

    Dim ws As Worksheet
    Dim newWS As Worksheet
    Dim Nom_Sauvegarde As String

    Application.DisplayAlerts = False

    Set ws = ActiveSheet
    ws.Copy: Set newWS = ActiveWorkbook.Sheets(1): newWS.Cells.Clear

    ws.Range("$A$1:$R$20").Copy newWS.Range("A1")
    Nom_Sauvegarde = InputBox("Entrer le nouveau nom de fichier :")

    With newWS
        .SaveAs ThisWorkbook.Path & "\" & Nom_Sauvegarde, xlTextWindows
        .Parent.Close
    End With

    Application.DisplayAlerts = True

End Sub
Rechercher des sujets similaires à "macro exportation txt selection precise"