[VBA Excel] Conversion xls vers csv

Résolu
Shooter78 Messages postés 12 Date d'inscription   Statut Membre Dernière intervention   -  
Shooter78 Messages postés 12 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
j'ai trouvé ceci sur internet me permettant de convertir des fichiers XLS possédant plusieurs feuilles en CSV.
Le soucis, je voudrais qu'il ne traite qu'une seul feuille (par exemple la feuille toto2)
Comment dois-je m'y prendre ?
Merci d'avance


Sub ConvertXLStoCSV()
On Error GoTo erreur
Application.ScreenUpdating = False
Dim curSheet As Worksheet, csvLine As String, csvSeparator As String, myFso, csvFile, i As Integer, j As Integer
Dim strXLSFile As String, strInputFolder As String, strOutputFolder As String
Dim strCSVFile As String
csvSeparator = ";"

'Change Input and Output folders to relevant location
strInputFolder = ThisWorkbook.Path & "\"
strOutputFolder = ThisWorkbook.Path & "\"
Set myFso = CreateObject("Scripting.FileSystemObject")

strXLSFile = Dir(strInputFolder & "*.xls")

Do While strXLSFile <> ""
If Not strInputFolder & strXLSFile = ThisWorkbook.Path & "\" & ThisWorkbook.Name Then
Workbooks.Open strInputFolder & strXLSFile
For Each curSheet In ActiveWorkbook.Sheets
With curSheet
strCSVFile = Left((strXLSFile), InStrRev(strXLSFile, ".") - 1) & "_" & .Name & ".csv"
Set csvFile = myFso.CreateTextFile(Filename:="C:/users/Administrateur/Desktop/" & strCSVFile, overwrite:=True)
For i = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
'initialiser la ligne CSV
csvLine = vbNullString
'boucler sur les 4 colonnes
For j = 1 To .Cells(1, .Columns.Count).End(xlToLeft).Column
'créer la ligne
csvLine = csvLine & IIf(csvLine = vbNullString, vbNullString, csvSeparator) & .Cells(i, j).Text
Next j
'écrire la ligne dans le fichier
csvFile.WriteLine csvLine
Next i
csvFile.Close
End With
Next curSheet
ActiveWorkbook.Close False
End If
strXLSFile = Dir
Loop
erreur:
Application.ScreenUpdating = True
End Sub
A voir également:

2 réponses

Yoda
 
Bonjour,

Remplacer
        For Each curSheet In ActiveWorkbook.Sheets
par
        Set curSheet = ActiveWorkbook.Sheets("toto2")

et supprimer la ligne
        Next curSheet

A+
0
Shooter78 Messages postés 12 Date d'inscription   Statut Membre Dernière intervention   3
 
Merci sa fonctionne,
0