
Sub importa_csv_gls()
Dim line As String
Dim arrayOfElements
Dim linenumber As Integer
Dim elementnumber As Integer
Dim element As Variant
linenumber = 0
elementnumber = 0
filepath = ActiveWorkbook.Path & " rack_gls.xls"
Open filepath For Input As #1 ' Open file for input
Do While Not EOF(1) ' Loop until end of file
linenumber = linenumber + 1
Line Input #1, line
arrayOfElements = Split(line, " ")
elementnumber = 0
For Each element In arrayOfElements
elementnumber = elementnumber + 1
Cells(linenumber, elementnumber).Value = element
Next
Loop
Close #1 ' Close file.
End Sub |
Private Function PrendiDati(percorso, nomefile, foglio, rif)
Dim arg As String
If Right(percorso, 1) <> "" Then percorso = percorso & "" 'controlliamo anche che nella stringa "percorso" sia stata inserita la barra
If Dir(percorso & nomefile) = "" Then
PrendiDati = "File Non Trovato"
Exit Function
End If
' usiamo la variabile "arg" assegnando la concatenazione dei valori reperiti con gli argomenti dalla macro "RilevaDati" - questa stringa non occorre modificarla
arg = "'" & percorso & "[" & nomefile & "]" & foglio & "'!" & Range(rif).Range("A1").Address(, , xlR1C1)
' Eseguiamo una XLM macro il cui risultato è assegnato alla funzione stessa
PrendiDati = ExecuteExcel4Macro(arg)
End Function
Sub Importa_track_gls()
Application.ScreenUpdating = False
Sheets("track_gls").Select
Cells.ClearContents
percorso = "C:UsersigorDesktopSPEDIZIONI"
file = "track_gls.xls"
foglio = "spedizioni"
For r = 1 To 50 ' numero righe
For c = 1 To 25 ' numero colonne , in questo caso dalla A alle E
cella = Cells(r, c).Address
Sheets("TRACK_GLS").Select
Cells(r, c) = PrendiDati(percorso, file, foglio, cella) ' richiamo della funzione
Application.ScreenUpdating = False
'Progressione.Hide
Next c
Next r
End Sub |
Sub BigMerge() ' copia uno sotto l'altro tutti i fogli di tutti i file
Set destWB = ActiveWorkbook
Dim DestCell As Range
FileNames = Application.GetOpenFilename( _
filefilter:="Excel Files (*.xls*),*.xls*", _
Title:="Select the workbooks to merge.", MultiSelect:=True)
If IsArray(FileNames) = False Then
If FileNames = False Then
Exit Sub
End If
End If
dr = 1
For N = LBound(FileNames) To UBound(FileNames)
Set WB = Workbooks.Open(fileName:=FileNames(N), ReadOnly:=True)
For Each ws In WB.Worksheets
With ws
If .UsedRange.Cells.Count > 1 Then
LR = destWB.Worksheets(1).Cells(Rows.Count, "A").End(xlUp).Row
.UsedRange.Copy destWB.Worksheets(1).Cells(dr, 1)
dr = ActiveSheet.UsedRange.Rows.Count + 2
End If
End With
Next ws
WB.Close savechanges:=False
Next N
End Sub
|
