
Sub eliminarighe()
Dim sh1 As Worksheet, fullnome As String, testo As String, inizio As Double
Dim conta As Double, Ncolonne As Integer, riga As Long, Col As Long, domanda
Dim i As Long, j As Long, matrice()
Application.ScreenUpdating = False
inizio = Timer
With ThisWorkbook
Set sh1 = .Worksheets("Foglio1")
End With
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "All files", "*.*"
.Filters.Add "text", "*.txt", 1
.Show
If .SelectedItems.Count = 0 Then
MsgBox ("Nessuna voce selezionata, procedura annullata")
GoTo esci
End If
fullnome = .SelectedItems(1)
End With
Open fullnome For Input As #1
dr = 1
trova = "NXWEB_TITOLO"
flag = 1
Do
Line Input #1, testo
If InStr(testo, trova) = 0 Then
Cells(dr, 1) = testo
dr = dr + 1
Else
Exit Do
End If
Loop
trova = "NXWEB_SIN_INCR_PRT"
While InStr(testo, trova) = 0
Line Input #1, testo
Wend
While Not EOF(1)
Line Input #1, testo
Cells(dr, 1) = testo
dr = dr + 1
Wend
Close #1
esci:
Application.ScreenUpdating = True
MsgBox Timer - inizio & " secondi"
End Sub |
Sub ReadCsv1()
Dim FileNum As Long, Filename As String, TotalFile As String, Records() As String
Filename = "F:Downloadordini.csv" ' <<<<<<<< change it
FileNum = FreeFile
Open Filename For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
Records = Split(TotalFile, vbcrlf)
......
End Sub |
Option Explicit
Sub eliminarighe()
Dim fullnome As String, inizio As Double
Dim FileNum As Long, TotalFile As String, Records() As String
Dim deletable As Boolean, s As String
Dim i As Long
Dim rec As Variant
Application.ScreenUpdating = False
inizio = Timer
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "All files", "*.*"
.Filters.Add "text", "*.txt", 1
.Show
If .SelectedItems.Count = 0 Then
MsgBox "Nessuna voce selezionata, procedura annullata"
Application.ScreenUpdating = True
MsgBox Timer - inizio & " secondi"
Exit Sub
End If
fullnome = .SelectedItems(1)
End With
FileNum = FreeFile
Open fullnome For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
Records = Split(TotalFile, vbCrLf)
deletable = False
For Each rec In Records
If InStr(rec, "NXWEB_TITOLO") > 0 Then deletable = True: Debug.Print "NXWEB_TITOLO at index " & i
If InStr(rec, "NXWEB_SIN_INCR_PRT") > 0 Then deletable = False: Debug.Print "NXWEB_SIN_INCR_PRT at index " & i
If Not deletable Then s = s & vbCrLf & rec
i = i + 1
Next
Close
Open fullnome & "_reduced.txt" For Binary As #FileNum
Put #1, , s & vbCrLf
Close
Application.ScreenUpdating = True
MsgBox "Finito in " & Timer - inizio & " secondi"
End Sub |
j = 0
For i = 1 To 5
Open "C:UsersPippoDesktop est_" & i & ".txt" For Binary As #1
For chunk = j + 0 To j + 3999
MyData = strData(chunk)
Put #1, , MyData & vbCrLf
Next
j = j + 4000
Close #1
Next |
Option Explicit
Sub eliminarighe()
Dim fullnome As String, inizio As Double
Dim FileNum As Long, TotalFile As String, Records() As String
Dim deletable As Boolean, s As String
Dim i As Long
Dim rec As Variant
Dim fso As Object, objTextFile As Object
Const ForReading As Integer = 1
Application.ScreenUpdating = False
inizio = Timer
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "All files", "*.*"
.Filters.Add "text", "*.txt", 1
.Show
If .SelectedItems.Count = 0 Then
MsgBox "Nessuna voce selezionata, procedura annullata"
Application.ScreenUpdating = True
MsgBox Timer - inizio & " secondi"
Exit Sub
End If
fullnome = .SelectedItems(1)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set objTextFile = fso.OpenTextFile(fullnome, ForReading)
TotalFile = objTextFile.ReadAll
objTextFile.Close
Records = Split(TotalFile, vbCrLf)
deletable = False
For Each rec In Records
If InStr(rec, "NXWEB_TITOLO") > 0 Then deletable = True: Debug.Print "NXWEB_TITOLO at index " & i
If InStr(rec, "NXWEB_SIN_INCR_PRT") > 0 Then deletable = False: Debug.Print "NXWEB_SIN_INCR_PRT at index " & i
If Not deletable Then s = s & vbCrLf & rec
i = i + 1
Next
Close
Open fullnome & "_reduced.txt" For Binary As #1
Put #1, , s & vbCrLf
Close
Application.ScreenUpdating = True
MsgBox "Finito in " & Timer - inizio & " secondi"
End Sub
|
Option Explicit
Sub eliminarighe()
Dim fullnome As String, inizio As Double
Dim s As String
Dim i As Long, j As Long
Dim wdApp As Object
Dim wdDoc As Object
Const ForReading As Integer = 1
Application.ScreenUpdating = False
inizio = Timer
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "All files", "*.*"
.Filters.Add "text", "*.txt", 1
.Show
If .SelectedItems.Count = 0 Then
MsgBox "Nessuna voce selezionata, procedura annullata"
Application.ScreenUpdating = True
MsgBox Timer - inizio & " secondi"
Exit Sub
End If
fullnome = .SelectedItems(1)
End With
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(fullnome)
'find start
wdDoc.Bookmarks("StartOfDoc").Select
wdApp.Selection.Find.Execute FindText:="NXWEB_TITOLO"
i = wdApp.Selection.Start
wdApp.Selection.MoveRight
'find end
wdApp.Selection.Find.Execute FindText:="NXWEB_SIN_INCR_PRT"
j = wdApp.Selection.End
'delete range
wdDoc.Range(Start:=i, End:=j).Delete
'save file
wdDoc.SaveAs fullnome & "_ridotto.txt"
wdDoc.Close
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub |
Public Const PAGE_READWRITE As Long = &H4
Public Const FILE_MAP_WRITE As Long = &H2
Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Public Const OPEN_ALWAYS = 4
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_BEGIN = 0
Public hFileMap As Long
Public hMM As Long
Public mapped_file As String
Public bound As Long
Public Declare Function GetFileSize Lib "Kernel32" ( _
ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Public Declare Function SetFilePointer Lib "Kernel32" ( _
ByVal hFile As Long, _
ByVal lDistanceToMove As Long, _
lpDistanceToMoveHigh As Long, _
ByVal dwMoveMethod As Long) As Long
Public Declare Function SetEndOfFile Lib "Kernel32" ( _
ByVal hFile As Long) As Long
Public Declare Function CreateFile Lib "Kernel32" Alias "CreateFileA" (ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Public Declare Function CreateFileMapping Lib "kernel32.dll" Alias "CreateFileMappingA" ( _
ByVal hFile As Long, _
ByVal lpFileMappigAttributes As Long, _
ByVal flProtect As Long, _
ByVal dwMaximumSizeHigh As Long, _
ByVal dwMaximumSizeLow As Long, _
ByVal lpName As String) As Long
Public Declare Function MapViewOfFile Lib "kernel32.dll" ( _
ByVal hFileMappingObject As Long, _
ByVal dwDesiredAccess As Long, _
ByVal dwFileOffsetHigh As Long, _
ByVal dwFileOffsetLow As Long, _
ByVal dwNumberOfBytesToMap As Long) As Long
Public Declare Function UnmapViewOfFile Lib "kernel32.dll" ( _
ByVal lpBaseAddress As Any) As Long
Public Declare Function CloseHandle Lib "kernel32.dll" ( _
ByVal hObject As Long) As Long
Public Declare Function ReadFile Lib "kernel32.dll" ( _
ByVal hFile As Long, _
ByRef lpBuffer As Any, _
ByVal nNumberOfBytesToRead As Long, _
ByRef lpNumberOfBytesRead As Long, _
ByVal lpOverlapped As Long) As Long
Public Declare Sub MoveMemory Lib "Kernel32" Alias "RtlMoveMemory" ( _
ByVal Destination As Long, _
ByVal Source As Long, _
ByVal Length As Long)
Public Declare Function MemCmp Lib "ntdll" Alias "RtlCompareMemory" ( _
ByVal Source1 As Long, Source2 As Any, _
ByVal Length As Long) As Long
Public Declare Function StrStr Lib "shlwapi.dll" Alias "StrStrA" ( _
ByVal lpszMin As Long, lpszSearch As Any) As Long
''''
Dim byFrom() As Byte
Dim byFromLen As Long
byFrom = StrConv("NXWEB_TITOLO" & Chr(0), vbFromUnicode)
byFromLen = UBound(byFrom)
Dim byTo() As Byte
Dim byToLen As Long
byTo = StrConv("NXWEB_SIN_INCR_PRT" & Chr(0), vbFromUnicode)
byToLen = UBound(byTo)
Dim hFile As Long
hFile = CreateFile("File.txt", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
Dim fLen As Long
fLen = GetFileSize(hFile, 0)
Dim hFileMap As Long
hFileMap = CreateFileMapping(hFile, 0, PAGE_READWRITE, 0, 0, 0)
Dim hMM As Long
hMM = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0)
Dim pFrom As Long
pFrom = StrStr(hMM, byFrom(0))
SetFilePointer hFile, pFrom - hMM, 0, FILE_BEGIN
Dim Ret As Long
Dim TxtBytes() As Byte
Dim s As String
ReDim TxtBytes(byFromLen) As Byte
ReadFile hFile, TxtBytes(0), byFromLen, Ret, 0
s = StrConv(TxtBytes, vbUnicode)
Dim pTo As Long
pTo = StrStr(pFrom, byTo(0))
SetFilePointer hFile, pTo - hMM, 0, FILE_BEGIN
ReDim TxtBytes(byToLen) As Byte
ReadFile hFile, TxtBytes(0), byToLen, Ret, 0
s = StrConv(TxtBytes, vbUnicode)
Dim pLen As Long
pLen = fLen + hMM - pTo - 1
MoveMemory pFrom, pTo, pLen
UnmapViewOfFile (hMM)
CloseHandle hFileMap
SetFilePointer hFile, fLen - (pTo - pFrom - 1), 0, FILE_BEGIN
SetEndOfFile hFile
CloseHandle hFile
|
pLen = fLen + hMM - pTo
...
SetFilePointer hFile, fLen - (pTo - pFrom), 0, FILE_BEGIN |
Dim hFile As Long
Dim fLen As Long
Dim byFrom() As Byte
Dim byFromLen As Long
byFrom = StrConv("NXWEB_TITOLO" & Chr(0), vbFromUnicode)
byFromLen = UBound(byFrom)
hFile = CreateFile("C:Usersgiuliana_a.AMMDesktopmemmappedFile.txt", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
fLen = GetFileSize(hFile, 0)
hFileMap = CreateFileMapping(hFile, 0, PAGE_READWRITE, 0, 0, 0)
hMM = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0)
Dim pFrom As Long
pFrom = StrStr(hMM, byFrom(0))
SetFilePointer hFile, pFrom - hMM, 0, FILE_BEGIN
UnmapViewOfFile (hMM)
CloseHandle hFileMap
SetEndOfFile hFile
CloseHandle hFile
|
Dim byTo() As Byte
Dim byToLen As Long
byTo = StrConv("FRASE DA CERCARE" & Chr(0), vbFromUnicode)
byToLen = UBound(byTo) ' 22
sfile = "F:TEST.txt"
dfile = "F:TEST_Ridotto.txt"
FileCopy sfile, dfile
Dim hFile As Long
hFile = CreateFile(dfile, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
Dim fLen As Long
fLen = GetFileSize(hFile, 0)
Dim hFileMap As Long
hFileMap = CreateFileMapping(hFile, 0, PAGE_READWRITE, 0, 0, 0)
Dim hMM As Long
hMM = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0)
Dim pTo As Long
pTo = StrStr(hMM, byTo(0))
SetFilePointer hFile, pTo - hMM, 0, FILE_BEGIN
Dim pLen As Long
pLen = fLen + hMM - pTo
MoveMemory hMM, pTo, pLen
UnmapViewOfFile (hMM)
CloseHandle hFileMap
SetFilePointer hFile, fLen - (pTo - hMM), 0, FILE_BEGIN
SetEndOfFile hFile
CloseHandle hFile |
Sub macro2()
Dim hFile As Long
Dim fLen As Long
Dim byFrom() As Byte
Dim byFromLen As Long
byFrom = StrConv("IM_DRB_FISC_FIR" & Chr(0), vbFromUnicode)
byFromLen = UBound(byFrom)
hFile = CreateFile("D:AGEST178_TXTGP_0.txt", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
fLen = GetFileSize(hFile, 0)
hFileMap = CreateFileMapping(hFile, 0, PAGE_READWRITE, 0, 0, 0)
hMM = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0)
Dim pFrom As Long
pFrom = StrStr(hMM, byFrom(0))
SetFilePointer hFile, pFrom - hMM, 0, FILE_BEGIN
UnmapViewOfFile (hMM)
CloseHandle hFileMap
SetEndOfFile hFile
CloseHandle hFile
End Sub |
Public Declare Function ReduceFile Lib "F:DocumentiExcelfileMacro-VBAMMFile.dll" _ (ByVal FileName As String, ByVal BlockStart As String, ByVal BlockStop As String) As Long Sub elimina_righe() ' da parola a parola Dim er As Long, sfile As String, dfile As String sfile = "F:DocumentiExcelfileMacro-VBALivorno.txt" dfile = "F:downloadLivornoRidotto.txt" FileCopy sfile, dfile er = ReduceFile(dfile, "ACQUARIO COMUNALE", "LA CUCINA LIVORNESE") 'er = ReduceFile(dfile, "ACQUARIO COMUNALE", "") End Sub |
Public Declare Function ReduceFile Lib "D:AGESTRIDUCI_FILE_TXTDllMMFile.dll" _ (ByVal FileName As String, ByVal BlockStart As String, ByVal BlockStop As String) As Long Sub elimina_righe() ' da parola a parola Dim er As Long, sfile As String, dfile As String sfile = "D:AGESTGP_01.txt" dfile = "D:AGESTGP_01_ridotto.txt" FileCopy sfile, dfile er = ReduceFile(dfile, "NXWEB_FORZA_VENDITA", "NXWEB_PVEND_COMP_ZONAINC") MsgBox (er) End Sub |
Public Declare Function ReduceFile Lib "D:AGESTRIDUCI_FILE_TXTDllMMFile.dll" _ (ByVal FileName As String, ByVal BlockStart As String, ByVal BlockStop As String) As Long Sub elimina_righe() ' da parola a parola Dim er As Long, sfile As String, dfile As String sfile = "D:AGESTGP_01.txt" er = ReduceFile(sfile, "NXWEB_FORZA_VENDITA", "NXWEB_PVEND_COMP_ZONAINC") MsgBox (er) End Sub |
