XL 2010 Macro export csv en ;

djam28

XLDnaute Occasionnel
Bonjour à tous,
J'ai une macro qui permet d'exporter ma feuille en csv et je voudrais la modifier de façon à ce que fichier exporté soit directement en ; et non en ,
La voici :

Public Sub SaveAsCSV1()
Dim wb As Workbook, ws As Worksheet
Dim strPath As String, strFilename As String
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Biobank_M0")
strPath = wb.Path & Application.PathSeparator
strFilename = "Biobank_M0.csv"
ws.Copy
With ActiveWorkbook
.SaveAs Filename:=strPath & strFilename, _
FileFormat:=xlCSV, _
local:=True '? adapter
.Close savechanges:=False
End With
End Sub

Merci de votre aide
Bonne journée
DE
 
Solution
Bonsoir,

à tester
VB:
Option Explicit
Public Sub SaveAsCSV1()
    Dim wb As Workbook, ws As Worksheet, plage As Range
    Dim strPath As String, strFilename As String
    Dim f As Integer, L As Integer, chaine As String, c As Integer
    Set wb = ThisWorkbook
    Set ws = wb.Worksheets("Biobank_M0")
    strPath = wb.Path & Application.PathSeparator
    strFilename = strPath & "/" & "Biobank_M0.csv"
    With ws
        Set plage = .UsedRange
        f = FreeFile()
        Open strFilename For Output As #f
        For L = 1 To plage.Rows.Count
            chaine = plage.Cells(L, 1)
            For c = 2 To plage.Columns.Count
                chaine = chaine & ";" & plage.Cells(L, c)
            Next c
            Print #f, chaine...

cp4

XLDnaute Barbatruc
Bonsoir,

à tester
VB:
Option Explicit
Public Sub SaveAsCSV1()
    Dim wb As Workbook, ws As Worksheet, plage As Range
    Dim strPath As String, strFilename As String
    Dim f As Integer, L As Integer, chaine As String, c As Integer
    Set wb = ThisWorkbook
    Set ws = wb.Worksheets("Biobank_M0")
    strPath = wb.Path & Application.PathSeparator
    strFilename = strPath & "/" & "Biobank_M0.csv"
    With ws
        Set plage = .UsedRange
        f = FreeFile()
        Open strFilename For Output As #f
        For L = 1 To plage.Rows.Count
            chaine = plage.Cells(L, 1)
            For c = 2 To plage.Columns.Count
                chaine = chaine & ";" & plage.Cells(L, c)
            Next c
            Print #f, chaine
        Next L
        Close #f
    End With
MsgBox "terminé!"
End Sub

Pour éditer correctement code sur XLD
Balise de code.gif
Bonne soirée.
 

djam28

XLDnaute Occasionnel
Bonsoir,

à tester
VB:
Option Explicit
Public Sub SaveAsCSV1()
    Dim wb As Workbook, ws As Worksheet, plage As Range
    Dim strPath As String, strFilename As String
    Dim f As Integer, L As Integer, chaine As String, c As Integer
    Set wb = ThisWorkbook
    Set ws = wb.Worksheets("Biobank_M0")
    strPath = wb.Path & Application.PathSeparator
    strFilename = strPath & "/" & "Biobank_M0.csv"
    With ws
        Set plage = .UsedRange
        f = FreeFile()
        Open strFilename For Output As #f
        For L = 1 To plage.Rows.Count
            chaine = plage.Cells(L, 1)
            For c = 2 To plage.Columns.Count
                chaine = chaine & ";" & plage.Cells(L, c)
            Next c
            Print #f, chaine
        Next L
        Close #f
    End With
MsgBox "terminé!"
End Sub

Pour éditer correctement code sur XLD
Regarde la pièce jointe 1137405
Bonne soirée.
Bonsoir Cp4,
Mille mercis ++++, ça fonctionne très bien et instantanée
Bonne soirée
 

cp4

XLDnaute Barbatruc
Bonjour,

Je souhaite faire la même chose mais pour exporter vers un SharePoint or la commande "Open.. for output" m'amène une erreur 52 "Nom de fichier ou numéro incorrect".
Sauriez-vous m'aider ?

Merci :)
Bonsoir,
On ne s'incruste pas ainsi dans une discussion. En tant que membre, tu peux ouvrir ta discussion, éventuellement joindre un fichier et mettre un lien vers cette discussion.

Bonne soirée.
 

M_Le_Blond

XLDnaute Nouveau
Bonjour @cp4,

je comprends.
Pardonne l'enthousiasme ou la désespérance d'un petit nouveau bloqué depuis plusieurs jours et qui a hâte de trouver une solution pour se sortir de cette impasse 😅
Voici un lien vers une discussion ouverte à ce sujet :

Merci pour l'aide que tu pourrais m'apporter.
Bonne journée.
 

Discussions similaires