file di testo



  • file di testo
    di stefanmi (utente non iscritto) data: 27/08/2013 15:11:08

    il mio programma genera un file di testo, nella colonna A c'e' la data però siccome è 01/01/13 i primi 12 giorni mi inverte il giorno con il mese, qualcuno mi spiega il motivo?



  • di Grograman data: 27/08/2013 15:15:49

    Cit: "la data però siccome è 01/01/13"

    File allegato:
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    01/02/13
    10/02/13
    12/02/13
    15/02/13
    15/02/13
    28/02/13

    occhio inoltre ad allegare dati sensibili. Tutti paesi vicino ai miei suoceri per altro!




  • di mabolsie data: 27/08/2013 18:45:26

    Ciao Gro... ho avuto anche io lo stesso problema in un programma non sono riuscito a capire il perchè comunque ho risolto facendo scrivere all'operatore la data con il punto anzichè la barra.
    es. 10.10.2013 e non 10/10/2013.

    Spero di esserti stato utile ciao

    Max



  • di Grograman data: 27/08/2013 19:13:29

    Ma ci sono un sacco di modi, anche cella = format(ladata,"mm/dd/yyyy"), solo che dalla spiegazione e dall'allegato non si capisce il problema



  • di stefanmi (utente non iscritto) data: 27/08/2013 19:34:03

    ho messo il file d'esempio era di febbraio, ma tutti i mesi inverte le date, però se noti nella 4 colonna non lo fa, quindi è un problema di programma? per la colonna 4 ho usato questa formula
    "=CONCATENA(STRINGA.ESTRAI(E1;1;6);20;STRINGA.ESTRAI(E1;7;2))"
    però per la colonna A forse dovrei usare una formula "SE"

    per i dati hai ragione starò piu' attento, di dove sei?



  • di Grograman data: 27/08/2013 21:25:02

    Casorezzo

    Cioè viviamo a Sesto, ma la fanciulla è originaria di Casures.

    Mi servirebbe vedere le date come sono in Excel e il codice che usi per esportarle (a sto punto perché non lo salvi in csv se devi esportarlo in txt?)



  • di stefanmi (utente non iscritto) data: 27/08/2013 21:57:24

    è il programma che li salva in "ASC" il file è quello che ho messo se lo importi in excel dovresti vedere come si vedono.

    P.S. conosco bene il Giuseppe della Pizzeria davanti alla chiesa di Casorezzo.



  • di stefanmi (utente non iscritto) data: 27/08/2013 22:07:33

    le importo con questa macro
     
    Sub estrai()
    '
    ' Macro4 Macro
    '
        ChDir "C:UsersstefanoDesktopluglio_13"
        myFile = Application.GetOpenFilename("text Files,*.asc")
        Workbooks.OpenText _
        Filename:=myFile, _
            Origin:=xlMSDOS, _
            StartRow:=1, _
            DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 1), Array( _
            8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(20, 1), Array(21, 1), Array(27, 1), _
            Array(28, 1), Array(36, 1), Array(37, 1), Array(42, 1), Array(43, 1), Array(78, 1), Array( _
            79, 1), Array(114, 1), Array(115, 1), Array(120, 1), Array(148, 1), Array(150, 1), Array( _
            151, 1)), TrailingMinusNumbers:=True
            
       
        ActiveSheet.Move Before:=Workbooks("esporta_rimborsi.xlsm").Sheets(1)
            
        Range("B:B,D:D,F:F,H:H,J:J,L:L,N:N,P:P,T:T").Select
        Range("T1").Activate
        Selection.Delete Shift:=xlToLeft
        Columns("A:L").Select
        Columns("A:L").EntireColumn.AutoFit
        
        Range("A1").Select
    End Sub



  • di Grograman data: 27/08/2013 22:42:11

    Continuo a non capire!
    Senza badare al dove andare a cercare il file, l'ho importato da testo registrandomi, e il formato rimane "gg/mm/aaaa".

    Se invece vuoi continuare ad importarlo in quel modo, modifica il tipo di dato per il primo array, importandolo come testo, dopo devi solo convertirlo in data, se passa di qui Isy gli chiediamo di farci un evaluate ad hoc
     
    Sub Macro1()
    Dim strFile As String, strPath As String
    
    strFile = "file_prova.ASC"
    strPath = "D:DocumentsDavideProve VBA"
    
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;" & strPath & strFile, Destination:=Range("$A$1"))
            .Name = "file_prova"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlOverwriteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 850
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = False
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = True
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    
    
    La tua importando il primo campo come testo:
    Sub estrai()
    ' Macro4 Macro
    '
        ChDir "D:DocumentsDavideProve VBA"
        myfile = Application.GetOpenFilename("text Files,*.asc")
        Workbooks.OpenText _
        Filename:=myfile, _
            Origin:=xlMSDOS, _
            StartRow:=1, _
            DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 2), Array( _
            8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(20, 1), Array(21, 1), Array(27, 1), _
            Array(28, 1), Array(36, 1), Array(37, 1), Array(42, 1), Array(43, 1), Array(78, 1), Array( _
            79, 1), Array(114, 1), Array(115, 1), Array(120, 1), Array(148, 1), Array(150, 1), Array( _
            151, 1)), TrailingMinusNumbers:=True
            
       
    '    ActiveSheet.Move Before:=Workbooks("esporta_rimborsi.xlsm").Sheets(1)
            
        Range("B:B,D:D,F:F,H:H,J:J,L:L,N:N,P:P,T:T").Delete Shift:=xlToLeft
        Columns("A:L").EntireColumn.AutoFit
        Range("A1").Select
    End Sub
     
    
    



  • di stefanmi (utente non iscritto) data: 27/08/2013 23:13:50

    02/01/2013
    02/02/2013
    02/03/2013
    02/04/2013
    02/05/2013
    02/06/2013
    02/07/2013
    02/08/2013
    02/09/2013
    02/10/2013
    02/11/2013
    02/12/2013
    13/02/13
    14/02/13
    15/02/13
    16/02/13
    17/02/13
    18/02/13
    19/02/13
    20/02/13
    21/02/13
    22/02/13
    23/02/13
    24/02/13
    25/02/13
    26/02/13
    27/02/13
    28/02/13
    a me li importa così



  • di Grograman data: 28/08/2013 08:27:15

    Mi sa che non hai letto il codice che ti ho postato sopra



  • di stefanmi (utente non iscritto) data: 28/08/2013 09:19:12

    ho cambiato l'indirizzo del file ma mi errore, ho sbagliato? scusa ma non sono espertissimo come si cambia array per farlo diventare file di testo?
     
    Sub Macro1()
    Dim strFile As String, strPath As String
    
    strFile = "file_prova.ASC"
    strPath = "C:UsersstefanoDesktopluglio_13"
    
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;" & strPath & strFile, Destination:=Range("$A$1"))
            .Name = "file_prova"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlOverwriteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 850
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = False
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = True
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub



  • di Grograman data: 28/08/2013 09:30:41

    Usa il tuo codice solito, ma:
     
    CAMBIA QUESTA RIGA
    
    FieldInfo:=Array(Array(0, 1), Array( _
    
    
    
    IN QUESTA
    
    FieldInfo:=Array(Array(0, 2), Array( _
    
    
    p.s. 1 = Generale, 2 = testo, 9 = non importare
    



  • di Grograman data: 28/08/2013 10:08:49

    Ti ho allegato un esempio, a te lo sviluppo
    E con sviluppo intendo, formattazoien campo CAP, intestazione colonne, salva con nome del file creato ecc ecc .

    Cosa fa: Apre una schermata di scelta file, importa il file doppiocliccato (che abbia la struttura dell'ASC che hai allegato tu).
    P.s. ma l'ultimo della lista fa l'assicuratore?
     
    Option Explicit
    Sub Sfoglia_Files()
    
      Dim strPath As String
      Dim FD As FileDialog
      Dim objFd As Variant
      Dim wb As Workbook
      Dim ws As Worksheet
      
      Set FD = Application.FileDialog(msoFileDialogFilePicker)
      With FD
        '.InitialFileName = "C:UsersstefanoDesktop"  'QUI PUOI METTERE IL PERCORSO INIZIALE, togli l'apice davanti alla riga se lo vuoi usare
        .Title = "Sfoglia cartelle"
        .ButtonName = "Ok"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewDetails
        .Show
        For Each objFd In .SelectedItems
        strPath = objFd
        Next objFd
      End With
      
      If strPath = "" Then GoTo Uscita
     
      Set wb = Application.Workbooks.Add
      Set ws = wb.Sheets(1)
      Call Query_ASC(strPath, ws)
      
      'qui inserire il codice per formattar ei CAP, inserire le intesazioni di colonna eccetera ;)
    Uscita:
      Set FD = Nothing
      Set wb = Nothing
      Set ws = Nothing
    End Sub
    
    
    Private Sub Query_ASC(ByVal strPath As String, ws As Worksheet)
        With ws.QueryTables.Add(Connection:="TEXT;" & strPath, Destination:=ws.Cells(1, 1)) 'mettere cells(2,1) se poi vuoi mettere le intestazioni di colonna
            .Name = "Query"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlOverwriteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 850
            .TextFileStartRow = 1
            .TextFileParseType = xlFixedWidth
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 2, 9, 1, 1, 1, 9, _
            1)
            .TextFileFixedColumnWidths = Array(8, 1, 1, 1, 9, 1, 6, 1, 8, 1, 5, 1, 35, 1, 3, 32, 1, 5, 28 _
            , 2, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        ws.Cells.EntireColumn.AutoFit
    End Sub
    



  • di stefanmi (utente non iscritto) data: 28/08/2013 13:48:17

    grazie

    P.S. non credo sia un assicuratore, ma non saprei



  • di stefanmi (utente non iscritto) data: 28/08/2013 14:31:48

    funziona tutto, l'unica cosa è che vorrei che sia importata nello stesso foglio della macro questa riga dove va messa e poi come faccio a cambiare il nome ogni volta della cartella?

    ActiveSheet.Move Before:=Workbooks("Cartel1").Sheets(1)
     
    Sub Sfoglia_Files()
    
      Dim strPath As String
      Dim FD As FileDialog
      Dim objFd As Variant
      Dim wb As Workbook
      Dim ws As Worksheet
      Dim x   As String
      Dim p   As String
      Dim LastRow As Long
      
      Set FD = Application.FileDialog(msoFileDialogFilePicker)
      With FD
        '.InitialFileName = "C:UsersstefanoDesktop"  'QUI PUOI METTERE IL PERCORSO INIZIALE, togli l'apice davanti alla riga se lo vuoi usare
        .Title = "Sfoglia cartelle"
        .ButtonName = "Ok"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewDetails
        .Show
        For Each objFd In .SelectedItems
        strPath = objFd
        Next objFd
      End With
      
      If strPath = "" Then GoTo Uscita
     
      Set wb = Application.Workbooks.Add
      Set ws = wb.Sheets(1)
      Call Query_ASC(strPath, ws)
     
        
        LastRow = [counta(A:A)]
        
        With Range("C1:C" & LastRow)
            x = .Address
            .Offset(, 0) = Evaluate("(" & x & ")/100")
        End With
        
        With Range("M1:M" & LastRow)
            p = .Address
            .Offset(, 0) = Evaluate("(" & p & ")/100")
        End With
      
      'qui inserire il codice per formattar ei CAP, inserire le intesazioni di colonna eccetera ;)
    Uscita:
      Set FD = Nothing
      Set wb = Nothing
      Set ws = Nothing
    End Sub
    
    
    Private Sub Query_ASC(ByVal strPath As String, ws As Worksheet)
        With ws.QueryTables.Add(Connection:="TEXT;" & strPath, Destination:=ws.Cells(1, 1)) 'mettere cells(2,1) se poi vuoi mettere le intestazioni di colonna
            .Name = "Query"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlOverwriteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 850
            .TextFileStartRow = 1
            .TextFileParseType = xlFixedWidth
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 2, 9, 1, 1, 1, 9, _
            1)
            .TextFileFixedColumnWidths = Array(8, 1, 1, 1, 9, 1, 6, 1, 8, 1, 5, 1, 35, 1, 3, 32, 1, 5, 28 _
            , 2, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        ws.Cells.EntireColumn.AutoFit
           ActiveSheet.Move Before:=Workbooks("Cartel1").Sheets(1) 
    End Sub



  • di stefanmi (utente non iscritto) data: 28/08/2013 14:51:48

    ce l'ho fatta, però come faccioa nominare il foglio che importo con il mese corrispondente con questa la chiama sempre foglio1
    ActiveSheet.Move Before:=Workbooks("importa_rimborsi.xlsm").Sheets(1)

    è giusto metterla come ultima riga?



  • di Grograman data: 28/08/2013 15:04:59

    Non ho capito bene dove e quando vuoi spostare il foglio, ma per crearlo nel file da cui lanci la macro.
     
    CAMBIA:
    
     Set wb = Application.Workbooks.Add
     Set ws = wb.Sheets(1)
    
    
    IN 
    
     Set wb = thisworkbook
     Set ws = wb.Sheets.add
    
    
    CAMBIA POI
    ws.Cells.EntireColumn.AutoFit
    ActiveSheet.Move Before:=Workbooks("Cartel1").Sheets(1) 
    
    
    IN
    ws.Cells.EntireColumn.AutoFit
    ws.move Before:=ws.parent.Sheets(1) 
    WS.name = format(ws.cells(1,1),"mmmm")



  • di stefanmi (utente non iscritto) data: 28/08/2013 15:05:13

    scusa un'altra cosa la via e il nome della via sono in 2 colonne diverse come posso metterle in un'unica colonna, grazie



  • di Grograman data: 28/08/2013 15:11:07

    se non ho scritto cavolate, sostituisci la routine di importazione con questa:
     
    Private Sub Query_ASC(ByVal strPath As String, ws As Worksheet)
        With ws.QueryTables.Add(Connection:="TEXT;" & strPath, Destination:=ws.Cells(1, 1)) 'mettere cells(2,1) se poi vuoi mettere le intestazioni di colonna
            .Name = "Query"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlOverwriteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 850
            .TextFileStartRow = 1
            .TextFileParseType = xlFixedWidth
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 2, 9, 1, 1, 1, 9, _
            1)
            .TextFileFixedColumnWidths = Array(8, 1, 1, 1, 9, 1, 6, 1, 8, 1, 5, 1, 35, 1, 35, 1, 5, 28 _
            , 2, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        With ws
          .Cells.EntireColumn.AutoFit
          .Name = Format(ws.Cells(1, 1), "mmmm yyyy")
          .Move .Parent.Sheets(1)
        End With
    End Sub



  • di Grograman data: 28/08/2013 15:14:37

    Di più non so se si può snellire
     
    Private Sub Query_ASC(ByVal strPath As String, ws As Worksheet)
      With ws.QueryTables.Add(Connection:="TEXT;" & strPath, Destination:=ws.Cells(1, 1)) 'mettere cells(2,1) se poi vuoi mettere le intestazioni di colonna
        .Name = "Query"
        .RefreshStyle = xlOverwriteCells
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlFixedWidth
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileTabDelimiter = True
        .TextFileColumnDataTypes = Array(1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 2, 9, 1, 1, 1, 9, 1)
        .TextFileFixedColumnWidths = Array(8, 1, 1, 1, 9, 1, 6, 1, 8, 1, 5, 1, 35, 1, 35, 1, 5, 28, 2, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
      End With
      With ws
        .Cells.EntireColumn.AutoFit
        .Name = Format(ws.Cells(1, 1), "mmmm yyyy")
        .Move .Parent.Sheets(1)
      End With
    End Sub
    



  • di stefanmi (utente non iscritto) data: 28/08/2013 19:41:22

    perfetto, sei un mago, comunque ci sono un sacco di modi per fare queste operazioni