Moderatori: Anthony47, Flash30005
Dim myFree
'
myFile = "C:\PROVA\TextTable.txt" '<<< Percorso e nome file
'
myFree = FreeFile
Open myFile For Output As #myFree
For i = 1 To UBound(Array2)
For j = 1 To UBound(Array2, 2)
myr = myr & ";" & Array2(i, j)
Next j
Print #myFree, Mid(myr, 2)
Next i
Close #myFree
Si fa presto a dire "scrivere il file", ma in che formato?
Ad esempio, se Array2 contiene un tot di righe * un tot di colonne allora il seguente codice scrive nel file "C:\PROVA\TextTable.txt" quel contenuto in formato "csv":
Dim myFree, I As Long, J As Long
'
myFile = "C:\PROVA\TextTable.txt" '<<< Percorso e nome file
'
myFree = FreeFile
Open myFile For Output As #myFree
For I = 1 To UBound(Array2)
myr = ""
For J = 1 To UBound(Array2, 2)
myr = myr & " " & Format(Array2(I, J), "00")
Next J
Print #myFree, Mid(myr, 2)
Next I
Close #myFree
11 133 33 04 55
05 13 07 11 12
Dim myFree, aInd As Long, J As Long
'
myFile = "C:\PROVA\TextTable.txt" '<<< Percorso e nome file
'
'a) Apertura file
myFree = FreeFile
Open myFile For Append As #myFree
'
'b) Scrittura di un record
myr = ""
For J = 1 To UBound(Array1, 2)
myr = myr & " " & Format(Array1(aInd, J), "00")
Next J
Print #myFree, Mid(myr, 2)
'
'c) Chiusura del file
Close #myFree
11 133 33 04 55
05 13 07 11 12
01 12 03 13 04
...portare la "fase a) Apertura file" in testa alla tua macro...
myr = myr & " " & Format(Array1(aInd, J), "00")
04 15 02 33 06
11 133 33 04 55
05 13 07 11 12
01 12 03 13 04
13 22 33 44 55
Next J
Debug.Print I, J, ">" & myr & "<" '<<< AGGIUNGI PER PROVA
Print #myFree, Mid(myr, 2)
Next I
1 6 > 04 15 02 33 06<
2 6 > 11 133 33 04 55<
3 6 > 05 13 07 11 12<
4 6 > 01 12 03 13 04<
5 6 > 13 22 33 44 55<
For J = 1 To UBound(Array2, 2)
If Len(Array2(I, J)) = 1 Then
myr = myr & " " & Array2(I, J)
Else
myr = myr & " " & Array2(I, J)
End If
Next J
If Len(Application.WorksheetFunction.TextJoin("", True, Array2)) < 2 Then
'che fare se l'array non ha contenuti?
'?
'
End If
... testare se Array2 e' vuoto, dipende anche da come e' stata dichiarato l'array...
If UBound(Array2)=1 Then
Exit Sub 'Array vuoto
End If
No, UBound(Array2) sara' 2 perche' nel ciclo era incluso Redim:ma se Array2 contiene 1 solo elemento NON VUOTO avrò
LBound(Array2) = UBound(Array2) = 1
for j = 1 to n
Array2(j) = ... 'Compila l'elemento attuale
Redim Preserve Array2( 1 to (UBound(Array2) + 1)) 'Aggiunge un elemento
next j
Torna a Applicazioni Office Windows
Inserire dati filtrati da 2 file ad un terzo file Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 14 |
File batch per copiare file selezionato da menu contestuale Autore: valle1975 |
Forum: Programmazione Risposte: 3 |
copia di dati da un file chiuso e elaborazione Autore: luca62 |
Forum: Applicazioni Office Windows Risposte: 2 |
Visitano il forum: Nessuno e 13 ospiti