Sub importa_pass()
Dim MyFile As String
Dim percorso As String
Dim FileTesto As String
Dim ur As Long
Sheets("report_pass").Select
Rows("2:20000").Select
Selection.ClearContents
Selection.ClearContents
percorso = "C:Users homasDesktopProgetti VBAproveprove" '< ""
FileTesto = percorso & "" & MyFile
Call ImpFilesTesto(FileTesto) 'chiamo il codice che importa i file
ur = Range("D" & Rows.count).End(xlUp).Row + 1 ' trovo l' Ultima Riga della colonna D occupata e aggiungo 1
Range("A4:A10").Copy ' copio il primo report importato
Range("D" & ur).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True ' lo incollo trasposto nella prima riga libera sul foglio report
Application.CutCopyMode = False
Range("A1:A60").ClearContents ' cancello il primo report importato dalla colonna A
MyFile = Dir()
Loop
End Sub
Sub ImpFilesTesto(FileTesto As String)
Dim nRiga As Long, nvo As Integer, nv As Integer
Dim nCol As Integer, Testo As String, Riga As String
Sheets("report_pass").Select
Open FileTesto For Input As #1
nRiga = Range("A65000").End(xlUp).Row
If nRiga = 1 Then
nRiga = 0
Else
nRiga = nRiga + 1
End If
leggiAncora:
nRiga = nRiga + 1
If Not EOF(1) Then
Line Input #1, Riga
nvo = 0: nCt = Len(Riga): nCol = 0
scanTesto:
nCol = nCol + 1
nv = InStr(nvo + 1, Riga, ",")
If nv = 0 Then
Testo = Right(Riga$, nCt - nvo)
Cells(nRiga, nCol) = Testo$
GoTo leggiAncora
End If
Testo = Mid(Riga$, nvo + 1, (nv - 1) - nvo)
nvo = nv
Cells(nRiga, nCol) = Testo
GoTo scanTesto
End If
Close #1
End Sub |