Bonjour à tous !
L’excellente macro ci-après permet d’enregistrer la feuille active au format CSV :
Sub ExportCSV()
' Export le contenu d'une feuille au format CSV et l'enregistre automatiquement dans le folder ou est stocké le fichier XLS.
Dim objF As Worksheet
Dim lngCellules As Long
Dim lngColonnes As Long
Dim i As Long
Dim R As Range
Dim j As Long
Dim fCond As FormatCondition
Dim strCSV As String
Dim sPath As String
Set objF = Excel.Active.Sheet
sPath = ThisWorkbook.Path & "\" & objF.Name & ".csv"
lngColonnes = objF.UsedRange.Columns.Count
lngCellules = objF.UsedRange.Rows.Count
For i = 1 To lngCellules
For j = 1 To lngColonnes
Set R = objF.Cells(i, j)
If R.NumberFormat = "@" Then
strCSV = strCSV & Chr(34) & R.Value & _
Chr(34) & IIf(j < lngColonnes, ";", "")
Else
strCSV = strCSV & IIf(R.NumberFormat <> _
"General", Format(R.Value, R.NumberFormat), _
R.Value) & IIf(j < lngColonnes, ";", "")
End If
Next
strCSV = strCSV & IIf(i < lngCellules, vbCrLf, "")
Next
If Len(strCSV) > 0 Then
Open sPath For Output As #1
Print #1, strCSV
Close #1
MsgBox "L'exportation c'est bien déroulé"
Else
MsgBox "Il n'y a aucune donnée dans la feuille active"
End If
Set R = Nothing
Set fCond = Nothing
Set objF = Nothing
End Sub
J’aimerai pouvoir enregistrer toutes les feuilles du classeur, hormis les 3 premières ou 3 noms de feuilles spécifiques. Or, lorsque je remplace : Set objF = Excel.Active.Sheet par Set objF = Excel.Worksheet, cela ne fonctionne pas.
Que fais-je de mal ?
Bonne journée à tous et merci.
Manu.
L’excellente macro ci-après permet d’enregistrer la feuille active au format CSV :
Sub ExportCSV()
' Export le contenu d'une feuille au format CSV et l'enregistre automatiquement dans le folder ou est stocké le fichier XLS.
Dim objF As Worksheet
Dim lngCellules As Long
Dim lngColonnes As Long
Dim i As Long
Dim R As Range
Dim j As Long
Dim fCond As FormatCondition
Dim strCSV As String
Dim sPath As String
Set objF = Excel.Active.Sheet
sPath = ThisWorkbook.Path & "\" & objF.Name & ".csv"
lngColonnes = objF.UsedRange.Columns.Count
lngCellules = objF.UsedRange.Rows.Count
For i = 1 To lngCellules
For j = 1 To lngColonnes
Set R = objF.Cells(i, j)
If R.NumberFormat = "@" Then
strCSV = strCSV & Chr(34) & R.Value & _
Chr(34) & IIf(j < lngColonnes, ";", "")
Else
strCSV = strCSV & IIf(R.NumberFormat <> _
"General", Format(R.Value, R.NumberFormat), _
R.Value) & IIf(j < lngColonnes, ";", "")
End If
Next
strCSV = strCSV & IIf(i < lngCellules, vbCrLf, "")
Next
If Len(strCSV) > 0 Then
Open sPath For Output As #1
Print #1, strCSV
Close #1
MsgBox "L'exportation c'est bien déroulé"
Else
MsgBox "Il n'y a aucune donnée dans la feuille active"
End If
Set R = Nothing
Set fCond = Nothing
Set objF = Nothing
End Sub
J’aimerai pouvoir enregistrer toutes les feuilles du classeur, hormis les 3 premières ou 3 noms de feuilles spécifiques. Or, lorsque je remplace : Set objF = Excel.Active.Sheet par Set objF = Excel.Worksheet, cela ne fonctionne pas.
Que fais-je de mal ?
Bonne journée à tous et merci.
Manu.