VBA
Sub SCRIVI_FILE_Click()
On Error GoTo Err
Dim V_TipoScrittura, V_NomeFile, V_Output As String
V_TipoScrittura = Cells(2, 2).Value
V_NomeFile = ActiveWorkbook.Path & "\prova.txt"
V_Output = ""
ApriFile V_TipoScrittura, V_NomeFile
Dim V_r, V_c As Long
If V_TipoScrittura = 1 Then
V_r = 1
Else
V_r = 2
End If
V_c = 5
While Cells(V_r, V_c).Value <> ""
While Cells(V_r, V_c).Value <> ""
If V_Output = "" Then
V_Output = Cells(V_r, V_c).Value
Else
V_Output = V_Output & Chr(9) & Cells(V_r, V_c).Value
End If
V_c = V_c + 1
Wend
ScriviFile V_Output
V_Output = ""
V_c = 5
V_r = V_r + 1
Wend
ChiudiFile
MsgBox ("Scritte " & V_r - 1 & " righe!")
uscita:
Exit Sub
Err:
MsgBox Err.Description
Resume uscita
End Sub
Sub LEGGI_FILE_Click()
On Error GoTo Err
Dim V_NomeFile As String
V_NomeFile = ActiveWorkbook.Path & "\prova.txt"
ApriFile 3, V_NomeFile
LeggiFile 1, 5
ChiudiFile
uscita:
Exit Sub
Err:
MsgBox Err.Description
Resume uscita
End Sub
Function ApriFile(Tipo, NomeFile)
If Tipo = 1 Then
Open NomeFile For Output As #1 'apre per sovrascrivere
ElseIf Tipo = 2 Then
Open NomeFile For Append As #1 'apre per accodare
ElseIf Tipo = 3 Then
Open NomeFile For Input As #1 'apre per leggere
Else
MsgBox ("Scegliere sovrascrivi/accoda/leggi")
Exit Function
End If
End Function
Function ScriviFile(Output)
Print #1, Output
End Function
Function LeggiFile(initR, initC)
Dim V_r, V_c As Long
V_r = initR
V_c = initC
Dim temp1, temp2 As String
temp1 = ""
temp2 = ""
Do While Not EOF(1)
temp1 = Input(1, #1)
If temp1 = Chr(9) Then
V_c = V_c + 1
Cells(V_r, V_c).Value = temp2
temp2 = ""
ElseIf temp1 = Chr(13) Then
V_r = V_r + 1
V_c = initC
temp2 = ""
ElseIf temp1 <> Chr(10) Then
temp2 = temp2 & temp1
Cells(V_r, V_c).Value = temp2
End If
Loop
End Function
Function ChiudiFile()
Close #1
End Function