Non riesco a salvare un foglio excel in formato csv con separatore ;

Anonimo
2021-06-28T14:18:47+00:00

Non riesco a salvare un foglio excel in formato CSV con separatore (;) punto e virgola

Questo il codice VBA

ActiveWorkbook.SaveAs Filename:= _

    "C:\Users\test\_screening\Documents\TAMPONI\" & nomefile, FileFormat:= \_ 

    xlCSVMSDOS, CreateBackup:=False 

ActiveWorkbook.Close SaveChanges:=True 

mi salva sempre con separatore (,) virgola

anche con questo codice vba

ActiveWorkbook.SaveAs Filename:= _

        "C:\Users\Gianmario\OneDrive\Documenti\rapidi.csv", FileFormat:=xlCSV, _

        CreateBackup:=False

Ho tentato in tutti i modi ma di da sempre il separatore (,) virgola

Grazie per le gentili risposte

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento
Risposta accettata dall'autore della domanda
Anonimo
2021-06-29T11:35:05+00:00

Ciao Gianmario,

Good morning Norman

Last thing

I noticed that:

Double quotes must be removed.

Immaginewhere should I act on the code

Nella macro ConvertireSeparatorePerCSV , sostituisci la riga:

sStr = sStr & """" & rCell.Value & """" & sSeparatoreVoluto

con:

sStr = sStr & rCell.Value & sSeparatoreVoluto

===

Regards,

Norman

La risposta è stata utile?

1 persona ha trovato utile questa risposta.
0 commenti Nessun commento

14 risposte aggiuntive

Ordina per: Più utili
  1. Anonimo
    2021-06-28T18:57:39+00:00

    I also see the file with separator;

    I am attaching the code

    'Salva molecolari 
    

    ActiveWorkbook.RefreshAll

    nomefile = Format(Date, "yyyymmdd") + "_" + Format(Time, "hhmm") + "_MOLECOLARI" + ".csv"

    ActiveWorkbook.RefreshAll 
    
      Sheets("MOLECOLARI").Select 
    
    Sheets("MOLECOLARI").Copy 
    

    '****************************************

     Dim srcRng As Range 
    
    Dim rRow As Range 
    
    Dim rCell As Range 
    
    Dim sStr As String 
    
    Dim FName As Variant 
    
    Const sSeparatoreVoluto As String = ";" 
    
    FName = Application.GetSaveAsFilename(nomefile, "CSV File (\*.csv), \*.csv") 
    
    If FName <> False Then 
    
    If Selection.Cells.Count > 1 Then 
    
    Set srcRng = Selection 
    
    Else 
    
    Set srcRng = ActiveSheet.UsedRange 
    
    End If 
    
    Open FName For Output As #1 
    
    For Each rRow In srcRng.Rows 
    
    sStr = "" 
    
    For Each rCell In rRow.Cells 
    
    sStr = sStr & """" & rCell.Value & """" & sSeparatoreVoluto 
    
    Next 
    
    While Right(sStr, 1) = sSeparatoreVoluto 
    
    sStr = Left(sStr, Len(sStr) - 1) 
    
    Wend 
    
    Print #1, sStr 
    
    Next 
    
    Close #1 
    
    End If 
    

    ActiveWorkbook.SaveAs Filename:= _

    **"C:\Users\test\_screening\Documents\TAMPONI\" & nomefile, FileFormat:= \_** 
    

    xlCSV, Local:=False, CreateBackup:=False

    ActiveWorkbook.Close SaveChanges:=True

    I already save the file in the right directory, but then the macro stops to ask for the file name again

    by

    gianmario

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2021-06-28T18:10:16+00:00

    Ciao Gianmario,

    After transforming the separator file (;) with your code, I need to save it

    which instruction should I use

    Because if I use my code it still saves it with the (,) comma

    Io ho esguito il codice sul seguente foglio, passando alla macro il nome del file myTest:

    Immagine

    Aprendo il file Test.csv con Blocco note, io vedo i dati separati da punto e virgola:

    Immagine

    ===

    Regards,

    Norman

    Immagine

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2021-06-28T17:50:21+00:00

    After transforming the separator file (;) with your code, I need to save it

    which instruction should I use

    Because if I use my code it still saves it with the (,) comma

    Buona giornata

    Gianm<rio Polenghi

    Bergamo

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2021-06-28T15:23:08+00:00

    Ciao Gianmario,

    Non riesco a salvare un foglio excel in formato CSV con separatore (;) punto e virgola

    Questo il codice VBA

    ActiveWorkbook.SaveAs Filename:= _

    "C:\Users\test_screening\Documents\TAMPONI" & nomefile, FileFormat:= _

    xlCSVMSDOS, CreateBackup:=False

    ActiveWorkbook.Close SaveChanges:=True

    mi salva sempre con separatore (,) virgola

    anche con questo codice vba

    ActiveWorkbook.SaveAs Filename:= _

            "C:\Users\Gianmario\OneDrive\Documenti\rapidi.csv", FileFormat:=xlCSV, _

            CreateBackup:=False

    Ho tentato in tutti i modi ma di da sempre il separatore (,) virgola

    Grazie per le gentili risposte

    Prova qualcosa del genere:

    '=========>>

    Option Explicit

    '--------->>

    Public Sub ConvertireSeparatorePerCSV()

    Dim srcRng As Range 
    
    Dim rRow As Range 
    
    Dim rCell As Range 
    
    Dim sStr As String 
    
    Dim FName As Variant 
    
    Const sSeparatoreVoluto As String = ";" 
    
    FName = Application.GetSaveAsFilename("", "CSV File (\*.csv), \*.csv") 
    
    If FName &lt;&gt; False Then 
    
        If Selection.Cells.Count &gt; 1 Then 
    
            Set srcRng = Selection 
    
        Else 
    
            Set srcRng = ActiveSheet.UsedRange 
    
        End If 
    
        Open FName For Output As #1 
    
        For Each rRow In srcRng.Rows 
    
            sStr = "" 
    
            For Each rCell In rRow.Cells 
    
                sStr = sStr & """" & rCell.Value & """" & sSeparatoreVoluto 
    
            Next 
    
            While Right(sStr, 1) = sSeparatoreVoluto 
    
                sStr = Left(sStr, Len(sStr) - 1) 
    
            Wend 
    
            Print #1, sStr 
    
        Next 
    
        Close #1 
    
    End If 
    

    End Sub

    '<<=========

    ===

    Regards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento