PeterTaylor
Board Regular
- Joined
- Aug 5, 2010
- Messages
- 158
Dear all,
I am running Excel 2013 on Windows 7.
I have the following macro, it opens a text file, looks for certain elements, and reports its findings to a spreadsheet.
The code seems to work fine. However, after it is processed 210 files I get the following error:
access violation at address 76f78e19 in module ntdll.dll. Write address of 00000014. Or a message telling me that I don't have enough memory. If I ex it Excel then reopen I can run the process again for a further 210 files. After a search of the web I have found out that Excel seems to not release its memory properly when opening and closing workbooks. Is this the case? Since I have about 6000 files to examine is there a workaround for this problem? Or is there another approach that I can use to examine of these files.
Regards,
Peter.
I am running Excel 2013 on Windows 7.
I have the following macro, it opens a text file, looks for certain elements, and reports its findings to a spreadsheet.
Code:
Sub checkfiles()
Dim mCol, mRow, mydata, myCount, myRowCount As Long
Dim counter, myversion, mySave As Integer
Dim vstring As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set wbWorkingList = ActiveWorkbook
mySave = 1
For Each MyList In wbWorkingList.Sheets("IMPORTLIST").Range("A:A").SpecialCells(xlCellTypeConstants)
Application.Workbooks.OpenText MyList.Value, origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=True, _
Comma:=True, Space:=True, Other:=False
Set wbText = ActiveWorkbook
Set found = wbText.Sheets(1).Columns("A").Find("H1000", , xlFormulas, xlWhole)
If found Is Nothing Then
'Set found = wbText.Sheets(1).Columns("A").Find("H01000", , xlFormulas, xlWhole)
'If found Is Nothing Then
With wbWorkingList.Sheets("Bad File").Range("A" & Rows.Count).End(xlUp).Offset(1)
.Value = MyList.Value
.Offset(, 1).Value = "No H1000"
GoTo myNextfile
End With
'End If
Else
'On Error GoTo point1
wbText.Sheets(1).Columns("A").Find("H1000", , xlFormulas, xlWhole).Activate
mydata = ActiveCell.Row
'GoTo point2
'point1:
'Resume Next
'wbText.Sheets(1).Columns("A").Find("H01000", , xlFormulas, xlWhole).Activate
'mydata = ActiveCell.Row
'point2:
wbText.Sheets(1).Range(Cells(mydata, 2), Cells(mydata, wbText.Sheets(1).UsedRange.Columns.Count)) _
.Copy Destination:=wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp).Offset(1).Offset(, 18)
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp).Offset(1)
.Value = MyList.Value
.Offset(, 11).Value = "OK"
'.Offset(, 19).Value = wbtext.Sheets(1).Range(Cells(mydata, 2), Cells(mydata, wbtext.Sheets(1).UsedRange.Columns.Count))
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0104", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 1).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 1).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0105", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 2).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 2).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0150", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 3).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 3).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0151", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 4).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 4).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0200", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 5).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 5).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0202", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 6).Value = "No"
End With
Else
wbText.Sheets(1).Columns("A").Find("H0202", , xlFormulas, xlWhole).Activate
counter = 1
mCol = ActiveCell.Column
mCol = mCol + 2
mRow = ActiveCell.Row
vstring = vbNullString
'Concatenate the next 10 cells in the row
While counter < 11
vstring = WorksheetFunction.Trim(vstring & " " & wbText.Sheets(1).Cells(mRow, mCol).Value)
counter = counter + 1
mCol = mCol + 1
Wend
'myversion = Val(vstring)
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 6).Value = vstring 'myversion
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0501", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 7).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 7).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0503", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 8).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 8).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0504", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 9).Value = "No"
End With
Else
wbText.Sheets(1).Columns("A").Find("H0504", , xlFormulas, xlWhole).Activate
counter = 1
mCol = ActiveCell.Column
mCol = mCol + 2
mRow = ActiveCell.Row
vstring = vbNullString
'Concatenate the next 10 cells in the row
While counter < 11
If IsNumeric(wbText.Sheets(1).Cells(mRow, mCol).Value) Then
vstring = WorksheetFunction.Trim(vstring & " " & CStr(wbText.Sheets(1).Cells(mRow, mCol).Value))
End If
vstring = WorksheetFunction.Trim(vstring & " " & wbText.Sheets(1).Cells(mRow, mCol).Value)
counter = counter + 1
mCol = mCol + 1
Wend
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 9).Value = vstring
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H0531", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 10).Value = "No"
End With
Else
wbText.Sheets(1).Columns("A").Find("H0531", , xlFormulas, xlWhole).Activate
counter = 1
mCol = ActiveCell.Column
mCol = mCol + 2
mRow = ActiveCell.Row
vstring = vbNullString
'Concatenate the next 10 cells in the row
While counter < 11
If IsNumeric(wbText.Sheets(1).Cells(mRow, mCol).Value) Then
vstring = WorksheetFunction.Trim(vstring & " " & CStr(wbText.Sheets(1).Cells(mRow, mCol).Value))
End If
vstring = WorksheetFunction.Trim(vstring & " " & wbText.Sheets(1).Cells(mRow, mCol).Value)
counter = counter + 1
mCol = mCol + 1
Wend
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 10).Value = vstring
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H1001", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 12).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 12).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H1002", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 13).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 13).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H1003", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 14).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 14).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("H1004", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 15).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 15).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("D", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 16).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 16).Value = "OK"
End With
End If
Set found = wbText.Sheets(1).Columns("A").Find("EOF", , xlFormulas, xlWhole)
If found Is Nothing Then
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 17).Value = "No"
End With
Else
With wbWorkingList.Sheets("Good Files").Range("A" & Rows.Count).End(xlUp)
.Offset(, 17).Value = "OK"
End With
End If
myNextfile:
mySave = mySave + 1
wbText.Close
If mySave = 20 Then
wbWorkingList.Save
mySave = 1
End If
Next MyList
Application.DisplayAlerts = True
Application.ScreenUpdating = True
wbWorkingList.Save
MsgBox ("fin")
End Sub
access violation at address 76f78e19 in module ntdll.dll. Write address of 00000014. Or a message telling me that I don't have enough memory. If I ex it Excel then reopen I can run the process again for a further 210 files. After a search of the web I have found out that Excel seems to not release its memory properly when opening and closing workbooks. Is this the case? Since I have about 6000 files to examine is there a workaround for this problem? Or is there another approach that I can use to examine of these files.
Regards,
Peter.