
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = 0 Then Exit Sub
mia_cartella = fd.SelectedItems(1)
Sheets("foglio1").Select
Set ff = CreateObject("Scripting.FileSystemObject").GetFolder(mia_cartella).Files
For Each f In ff
If Right(f, 9) = ".DMO_CAPT" Or Right(f, 4) = ".DMO" Then
With ActiveSheet.QueryTables.Add(Connection:="text;" & f, Destination:=[a1])
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
Next |
Dim sPathNome As Variant
sPathNome = Application.GetOpenFilename( _
"File di testo (*.txt),*.txt", _
, "Selezionare un report")
If sPathNome <> False Then
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & sPathNome, Destination:=Range("A1")) |
v = Split(f.Name, "_")
Sheets("eCAV").Cells(i, 4) = Left(v(3), 5) 'numero report
Sheets("eCAV").Cells(i, 3) = v(1) 'np
Sheets("eCAV").Cells(i, 2) = v(0) 'codice
i = i + 1 |
Sub solo_numeri()
Dim num As Variant
s = "MiaStringa123"
For i = 1 To Len(r)
If IsNumeric(Mid(s, i, 1)) Then
num = num + Mid(s, i, 1)
End If
Next
MsgBox "Il numero inserito nella stringa é " & num
End Sub |
Function estrai_numeri(s As String) As Collection
'restituisce una collection di numeri
'utilizzo:
'Set new_collection = estrai_numeri(stringa)
'poi si può ciclare in new_colelction per recuperare i valori memorizzati
Dim re As Object, ma As Object, v As Collection
Set re = CreateObject("VBScript.Regexp")
Set v = New Collection
re.Pattern = "d+"
re.Global = True
re.ignorecase = True
For Each ma In re.Execute(s)
v.Add ma
Next
Set estrai_numeri = v
End Function
Function estrai_numeri(ByVal source As String) As Long
'conserva solo i caratteri numerici; sostituisce tutti gli altri caratteri non alfabetici con ""
'utilizzo:
'i = estrai_numeri(stringa)
Dim i As Long, t As String, s As String
s = source
For i = 1 To Len(s)
t = Mid(s, i, 1)
If t Like "*[!0-9]*" Then source = Replace(source, t, "")
Next
estrai_numeri = CLng(source)
End Function |
Sub inverti_vettore(vector() As String)
Dim i As Long, maximum As Long, minimum As Long, tmp As String
minimum = LBound(vector)
maximum = UBound(vector)
For i = minimum To minimum + (maximum - minimum) 2
tmp = vector(i)
vector(i) = vector(maximum + minimum - i)
vector(maximum + minimum - i) = tmp
Next
End Sub |
For i = UBound(lista) - 1 To 1 Step -1
For j = 1 To i
'per ordinare dal maggiore inverti con "<"
If lista(j) > lista(j + 1) Then
Temp = lista(j)
lista(j) = lista(j + 1)
lista(j + 1) = Temp
End If
Next j
Next i
|
v = Split(f.Name, "_")
num = ""
k = 1
For t = 1 To Len(v(3)) 'estrae numeri da stringa
If IsNumeric(Mid(v(3), t, 1)) Then
num = num + Mid(v(3), t, 1)
vett(k) = num
k = k + 1
End If
Next
Sheets("eCAV").Cells(i, 4) = vett(k) 'numero report
Sheets("eCAV").Cells(i, 2) = v(0) 'codice
If v(2) Like "NP*" Then
Sheets("eCAV").Cells(i, 3) = v(2) 'np
Else
Sheets("eCAV").Cells(i, 3) = v(1)
End If
k = k - 1
i = i + 1 |
i = 25
Set ff = CreateObject("Scripting.FileSystemObject").GetFolder(mia_cartella).Files
For Each f In ff
If UCase(Right(f, 9)) = ".DMO_CAPT" Or UCase(Right(f, 4)) = ".DMO" Then
With ActiveSheet.QueryTables.Add(Connection:="text;" & f, Destination:=[a1])
.Name = "SOM59054_NP2216552_BFA_REP1_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
Dim vett() As String
'On Error GoTo asd
v = Split(f.Name, "_")
num = ""
k = 1
For t = 1 To Len(v(3)) 'estrae numeri da stringa
If IsNumeric(Mid(v(3), t, 1)) Then
num = num + Mid(v(3), t, 1)
End If
Next
vett(k) = num 'inserisce numeri nel vettore
k = k + 1
Sheets("eCAV").Cells(i, 2) = v(0) 'codice
If v(2) Like "NP*" Then
Sheets("eCAV").Cells(i, 3) = v(2) 'np
Else
Sheets("eCAV").Cells(i, 3) = v(1)
End If
'k = k - 1
i = i + 1
'asd:
End With
End If
Next
i = 25
For k = 10 To 1 Step -1 'inserisce il vettore nel foglio dei risltati facendolo scorrere
'al contrario
Sheets("eCAV").Cells(i, 4) = vett(k)
i = i + 1
Next
|
