
Open "C:PROVAMULTIPLO.TXT" For Input As #1 CONTA = 0 Do Until EOF(1) Line Input #1, DATA DATO = Mid(DATA, 1, 1) If DATO = 8 Then CONTA = CONTA + 1 End If Loop Close For I = 1 To CONTA Open "C:PROVAMULTIPLO.TXT" For Input As #1 Open "C:" & I & ".TXT" For Output As #2 Do Until EOF(1) Line Input #1, DATA DATO = Mid(DATA, 1, 1) If DATO = 0 Or DATO = 1 Or DATO = 2 Or DATO = 8 Then Print #2, DATA Close End If Loop Close Next I |
Option Explicit
Public I As Integer, Scritti As Integer, Dato_Letto As String, Nome_Inp As String, Nome_Out As String, Nome_App As String
Sub Dividi_File()
Nome_Inp = "C:Multiplo.txt"
On Error GoTo Errore1
Open Nome_Inp For Input As #1
Nome_Out = "Multiplo_"
I = 1
Do Until EOF(1)
Line Input #1, Dato_Letto
If Mid(Dato_Letto, 1, 1) = 0 Then
On Error GoTo Errore2
Nome_App = "C:" & Nome_Out & Format(I, "00") & ".txt"
Open Nome_App For Output As #2
Scritti = 0
End If
Print #2, Dato_Letto
Scritti = Scritti + 1
If Mid(Dato_Letto, 1, 1) = 9 Then
Close 2
MsgBox "Effettuata scrittura del file: " & Nome_App & " con " & Scritti & " record"
I = I + 1
End If
Loop
Close 1
GoTo Fine
Errore1:
MsgBox "Errore sul file: " & Nome_Inp
GoTo Fine
Errore2:
MsgBox "Errore sul file: " & Nome_Out
Fine:
MsgBox "Fine Elaborazione. Scritti: " & I - 1 & " File"
End Sub |
Option Explicit
Public I As Integer, Scritti As Integer, Dato_Letto As String, Nome_Inp As String, Nome_Out As String, Nome_App As String
Sub Dividi_File()
Nome_Inp = "C:UsersENZOMULTIPLO.TXT"
On Error GoTo Errore1
Open Nome_Inp For Input As #1
Nome_Out = "Multiplo_"
I = 1
Do Until EOF(1)
Line Input #1, Dato_Letto
If Mid(Dato_Letto, 1, 1) = 0 Then
On Error GoTo Errore2
Nome_App = "C:UsersENZO" & Nome_Out & Format(I, "00") & ".txt"
Open Nome_App For Output As #2
Scritti = 0
End If
Print #2, Dato_Letto
Scritti = Scritti + 1
If Mid(Dato_Letto, 1, 1) = 9 Then
Close 2
MsgBox "Effettuata scrittura del file: " & Nome_App & " con " & Scritti & " record"
I = I + 1
End If
Loop
Close 1
GoTo Fine
Errore1:
MsgBox "Errore sul file: " & Nome_Inp
GoTo Fine
Errore2:
MsgBox "Errore sul file: " & Nome_Out
Fine:
MsgBox "Fine Elaborazione. Scritti: " & I - 1 & " File"
End Sub
|
ossia se nel file di input ho 0apertura 1aaaaa 2aaaaa 2aaaaa 2aaaaa 8aaaaa 1bbbbb 2bbbbb 2bbbbb 8bbbbb 9chiusura '''''''''''''''''''''''''' dovro' avere il primo file 0apertura 1aaaaa 2aaaaa 2aaaaa 2aaaaa 8aaaaa 9chiusura '''''''''''''''''''''''' il secondo file 0apertura 1prova 2bbbbb 2bbbbb 8bbbbb 9chiusura etc etc |
ossia se nel file di input ho 0apertura 1aaaaa 2aaaaa 2aaaaa 2aaaaa 8aaaaa 1bbbbb 2bbbbb 2bbbbb 8bbbbb 9chiusura '''''''''''''''''''''''''' dovro' avere il primo file 0apertura 1aaaaa 2aaaaa 2aaaaa 2aaaaa 8aaaaa 9chiusura '''''''''''''''''''''''' il secondo file 0apertura 1bbbbb 2bbbbb 2bbbbb 8bbbbb 9chiusura etc etc |
Sub DividiFile()
Dim Matrice()
ReDim Matrice(10000)
NumFile% = FreeFile
NomeFile = 1
Open "C:Tuo PercorsoMULTIPLO.TXT" For Input As #1
Do Until EOF(1)
Line Input #1, Data
I = I + 1
Matrice(I) = Data
Loop
Close #1
ReDim Preserve Matrice(I)
Open "C:Tuo Percorso" & NomeFile & ".TXT" For Output As #NumFile
For II = LBound(Matrice) + 1 To UBound(Matrice)
If Mid(Matrice(II), 1, 1) < 8 Then
Print #NumFile%, Matrice(II)
Else
NomeFile = NomeFile + 1
Print #NumFile%, Matrice(II)
If II < UBound(Matrice) Then
Print #NumFile%, "9Chiusura"
Close #NumFile%
If UBound(Matrice) = II + 1 Then Exit Sub
Open "C:Tuo Percorso" & NomeFile & ".TXT" For Output As #NumFile%
Print #NumFile%, "0Apertura"
End If
End If
Next II
End Sub
|
Option Explicit
Public I As Integer, Scritti As Integer, Dato_Letto As String, Nome_Inp As String, Nome_Out As String, Nome_App As String
Public Tipo_0 As String, Tipo_9 As String
Sub Dividi_File()
Nome_Inp = "C:Multiplo.txt"
On Error GoTo Errore1
Open Nome_Inp For Input As #1
Nome_Out = "Multiplo_"
I = 1
Do Until EOF(1)
Line Input #1, Dato_Letto
If Mid(Dato_Letto, 1, 1) = 0 Then
Tipo_0 = Dato_Letto
End If
If Mid(Dato_Letto, 1, 1) = 9 Then
Tipo_9 = Dato_Letto
End If
Loop
Close 1
On Error GoTo Errore1
Open Nome_Inp For Input As #1
Do Until EOF(1)
Line Input #1, Dato_Letto
If Mid(Dato_Letto, 1, 1) = 9 Then
Close 2
Exit Do
End If
If Mid(Dato_Letto, 1, 1) = 1 Then
On Error GoTo Errore2
Nome_App = "C:" & Nome_Out & Format(I, "00") & ".txt"
Open Nome_App For Output As #2
Print #2, Tipo_0
Scritti = 1
End If
If Mid(Dato_Letto, 1, 1) <> 0 Then
Print #2, Dato_Letto
Scritti = Scritti + 1
End If
If Mid(Dato_Letto, 1, 1) = 8 Then
Print #2, Tipo_9
Scritti = Scritti + 1
Close 2
MsgBox "Effettuata scrittura del file: " & Nome_App & " con " & Scritti & " record"
I = I + 1
End If
Loop
Close 1
GoTo Fine
Errore1:
MsgBox "Errore sul file: " & Nome_Inp
Close 1
Exit Sub
Errore2:
MsgBox "Errore sul file: " & Nome_Out
Close 1
Exit Sub
Fine:
MsgBox "Fine Elaborazione. Scritti: " & I - 1 & " File"
End Sub
|
Sub DividiFile_Big()
Dim Matrice()
ReDim Matrice(10000)
NumFile% = FreeFile
NomeFile = 1
Open "C:MULTIPLO.TXT" For Input As #1
Do Until EOF(1)
Line Input #1, Data
I = I + 1
Matrice(I) = Data
Loop
Close #1
ReDim Preserve Matrice(I)
Open "C:" & Format(NomeFile, "000") & ".TXT" For Output As #NumFile
For II = LBound(Matrice) + 1 To UBound(Matrice)
If Mid(Matrice(II), 1, 1) < 8 Then
Print #NumFile%, Matrice(II)
Else
NomeFile = NomeFile + 1
Print #NumFile%, Matrice(II)
If II < UBound(Matrice) Then
Print #NumFile%, Matrice(UBound(Matrice)) '"9Chiusura"
Close #NumFile%
If UBound(Matrice) = II + 1 Then
Exit Sub
End If
Open "C:" & Format(NomeFile, "000") & ".TXT" For Output As #NumFile%
Print #NumFile%, Matrice(1) '"0Apertura"
End If
End If
Next II
End Sub |
Sub DividiFile_Big()
Dim Matrice()
Dim Intervallo As Range, Indirizzo As String
Set Intervallo = ActiveSheet.Range("A1:A" & Range("a65536").End(xlUp).Row)
For Each Cella In Intervallo
Indirizzo = Cella
Erase Matrice
ReDim Matrice(10000)
NumFile% = FreeFile
NomeFile = 1
Open Indirizzo For Input As #1
Do Until EOF(1)
Line Input #1, Data
I = I + 1
Matrice(I) = Data
Loop
Close #1
ReDim Preserve Matrice(I)
Open "C:" & Format("M" & NomeFile, "000") & ".TXT" For Output As #NumFile
For II = LBound(Matrice) + 1 To UBound(Matrice)
If Mid(Matrice(II), 1, 1) < 8 Then
Print #NumFile%, Matrice(II)
Else
NomeFile = NomeFile + 1
Print #NumFile%, Matrice(II)
If II < UBound(Matrice) Then
Print #NumFile%, Matrice(UBound(Matrice)) '"9Chiusura"
Close #NumFile%
If UBound(Matrice) = II + 1 Then Exit Sub
Open "C:" & Format(NomeFile, "000") & ".TXT" For Output As #NumFile%
Print #NumFile%, Matrice(1) '"0Apertura"
End If
End If
Next II
I = 0
Next
End Sub |
Option Explicit
Public I As Integer, Scritti As Integer, Scritti_Tot As Integer, Dato_Letto As String, Nome_Inp As String, Nome_Out As String, Nome_App As String
Public Tipo_0 As String, Tipo_9 As String
Public Riga As Integer, Num_file As Integer
Sub Dividi_File_Nuova()
Scritti_Tot = 0
Num_file = Range("A" & Rows.Count).End(xlUp).Row
For Riga = 2 To Num_file
Nome_Inp = Foglio1.Cells(Riga, 1) '"C:Multiplo.txt"
On Error GoTo Errore1
Open Nome_Inp For Input As #1
Nome_Out = Left(Foglio1.Cells(Riga, 1), Len(Foglio1.Cells(Riga, 1)) - 4) & "_"
I = 1
Do Until EOF(1)
Line Input #1, Dato_Letto
If Mid(Dato_Letto, 1, 1) = 0 Then
Tipo_0 = Dato_Letto
End If
If Mid(Dato_Letto, 1, 1) = 9 Then
Tipo_9 = Dato_Letto
End If
Loop
Close 1
On Error GoTo Errore1
Open Nome_Inp For Input As #1
Do Until EOF(1)
Line Input #1, Dato_Letto
If Mid(Dato_Letto, 1, 1) = 9 Then
Close 2
Exit Do
End If
If Mid(Dato_Letto, 1, 1) = 1 Then
On Error GoTo Errore2
Nome_App = Nome_Out & Format(I, "000") & ".txt"
Open Nome_App For Output As #2
Print #2, Tipo_0
Scritti = 1
End If
If Mid(Dato_Letto, 1, 1) <> 0 Then
Print #2, Dato_Letto
Scritti = Scritti + 1
End If
If Mid(Dato_Letto, 1, 1) = 8 Then
Print #2, Tipo_9
Scritti = Scritti + 1
Close 2
'.....................................
' La seguente isctruzione la puoi togliere dopo aver fatto le prove
MsgBox "Effettuata scrittura del file: " & Nome_App & " con " & Scritti & " record"
'.....................................
I = I + 1
End If
Loop
Close 1
Scritti_Tot = Scritti_Tot + I - 1
'.....................................
' Questa vedi tu se lasciarla o meno
MsgBox "Effettuata scrittura di: " & I - 1 & " file partendo da: " & Nome_Inp
'.....................................
Next Riga
GoTo Fine
Errore1:
MsgBox "Errore sul file: " & Nome_Inp
Close 1
Exit Sub
Errore2:
MsgBox "Errore sul file: " & Nome_Out
Close 1
Exit Sub
Fine:
MsgBox "Fine Elaborazione. Scritti: " & Scritti_Tot & " File"
End Sub |
sub duplica()
P = 1
Open "C:PROVA.TXT" For Input As #1
Open "C:DUPLICATO.TXT" For Output As #2
Do Until EOF(1)
Line Input #1, DATA
Record = Mid(DATA, 1, 1)
If Record = 2 Then
DIST = Mid(DATA, 74, 8)
DATA = Replace(DATA, DIST, Foglio3.Range("B" & P))
Debug.Print DATA
End If
P = P + 1
Print #2, DATA
Loop
Close
end sub |
Option Explicit
Public P As Integer, Dati As String, File_Inp As String, File_Out As String
Sub Duplica()
P = 1
File_Inp = "PROVA.TXT"
File_Out = "DUPLICATO.TXT"
On Error GoTo Errore1
Open File_Inp For Input As #1
On Error GoTo Errore2
Open File_Out For Output As #2
Do Until EOF(1)
Line Input #1, Dati
If Mid(Dati, 1, 1) = 2 Then
Dati = Mid(Dati, 1, 73) & Foglio3.Range("B" & P)
P = P + 1
End If
On Error GoTo Errore3
Print #2, Dati
Loop
GoTo Fine
Errore1:
MsgBox "Errore sul file: " & File_Inp
GoTo Fine
Errore2:
MsgBox "Errore sul file: " & File_Out
GoTo Fine
Errore3:
MsgBox "Errore in scrittura del file: " & File_Out
GoTo Fine
Fine:
Close
End Sub
|
Option Explicit
Public P As Integer, Part As Integer, Ri_Part As Integer, Lung As Integer, Per_Lung As Integer
Public Dati As String, File_Inp As String, File_Out As String
Sub Duplica()
P = 1
Part = 74
Lung = 8
Ri_Part = Part + Lung
File_Inp = "PROVA.TXT"
File_Out = "DUPLICATO.TXT"
On Error GoTo Errore1
Open File_Inp For Input As #1
On Error GoTo Errore2
Open File_Out For Output As #2
Do Until EOF(1)
Line Input #1, Dati
If Mid(Dati, 1, 1) = 2 Then
Per_Lung = Len(Dati) - Ri_Part + 1
Dati = Mid(Dati, 1, (Part - 1)) & Foglio3.Range("B" & P) & Mid(Dati, Ri_Part, Per_Lung)
P = P + 1
If Foglio3.Range("B" & P) = "" Then
MsgBox "Elaborazione Interrotta - Controllare i dati nel Foglio 3 - Cella 'B" & P & "'"
Exit Do
End If
End If
On Error GoTo Errore3
Print #2, Dati
Loop
GoTo Fine
Errore1:
MsgBox "Errore sul file: " & File_Inp
GoTo Fine
Errore2:
MsgBox "Errore sul file: " & File_Out
GoTo Fine
Errore3:
MsgBox "Errore in scrittura del file: " & File_Out
Fine:
Close
End Sub
|
