Home |
Search |
Today's Posts |
#15
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Joel,
Just want to make sure I understand you correctly.. You want me to delete these lines: Set masterSht = Nothing Set Master = Nothing xlApp.Quit Set xlApp = Nothing 'ADDED FOR MEMORY or get rid of the xlApp reference all together? Is the purpose to release the extra Excel's in Task Manager or stop the blinking? Thanks, MikeZz "Joel" wrote: I don't think the appl is really savving memory. try again without the appl Sub ReadNewContract(fileNo, arrMaster) Dim MasterFile Dim f, c, r Dim lngCount As Long Dim arrTemp() As Variant Dim Master As Workbook Dim masterSht As Worksheet Dim rowsMaster, colsMaster, lastCellMaster Dim rowMax, rightCol Dim FoundIndent Dim matCount, matTotal Dim ctCellMaster Dim testRowCountMat Dim alertStat Dim tempXLFile Dim xlApp As New Excel.Application 'ADDED FOR MEMORY Dim FileString As String 'ADDED FOR MEMORY xlApp.Application.Visible = True 'ADDED FOR MEMORY '################################################# ########################################### '########### READ IN MASTER FILE '################################################# ########################################### If fileNo = 1 Or IsEmpty(fileLocExcel) Then fileLocExcel = Get_File_Info(arrFiles(fileNo, colFileName), "Directory") End If FileString = arrFiles(fileNo, colFileName) 'ADDED FOR MEMORY xlApp.Workbooks.Open (FileString) 'Focus is now on the workbook 'ADDED FOR MEMORY Set Master = ActiveWorkbook Set masterSht = .ActiveSheet MasterFile = Master.Name lastCellMaster = LastCellIn(masterSht) rowsMaster = LastRowIn(masterSht) arrFiles(fileNo, colFileRows) = rowsMaster colsMaster = LastColIn(masterSht) colsMaster = Mid(Cells(1, colsMaster).Address, 2, 1) If rowsMaster = Empty Or colsMaster = Empty Then 'File was not converted to Excel propertly arrFiles(fileNo, colFileStat) = "Empty File" Master.Close SaveChanges:=False errCount = errCount + 1 ' 1 'KeyErr Anchor: Name arrErrors(errCount, colKeyErrFile) = _ Get_File_Info(arrFiles(fileNo, colFileName), "FileName") ' 2 'KeyErrAnchor: Anchor or Code arrErrors(errCount, colKeyErrCode) = "Empty Excel File" ' 3 'KeyErr Anchor: Name arrErrors(errCount, colKeyErrDesc) = "Empty Excel File" ' KeyErr Anchor:Special Function to perform (such as count repeats) arrErrors(errCount, colKeyErrStat) = "Empty Excel File" Exit Sub End If ctCellMaster = 0 arrTemp = masterSht.Range("A1:" & colsMaster & rowsMaster).Value arrMaster = arrTemp Master.Close SaveChanges:=False 'Application.DisplayAlerts = alertStat End Sub "MikeZz" wrote: Hi Joel, Below is the code I am currently testing: I've tried to use the Application.ScreenUpdating = False in the procedure that calls this one but I still get the blinking (Focusing and Refocusing on Excel). I also seem to have another dilema. On my computer at Home, Task Manager only had shown the single Excel Task when I was all done. At work, it shows a new task for each file I open and both the qty of Processes and Memory Usage continues to grow. Is there an options setting somewhere that is impacting this? Thanks again for all your help, Sub ReadNewContract(fileNo, arrMaster) Dim MasterFile Dim f, c, r Dim lngCount As Long Dim arrTemp() As Variant Dim Master As Workbook Dim masterSht As Worksheet Dim rowsMaster, colsMaster, lastCellMaster Dim rowMax, rightCol Dim FoundIndent Dim matCount, matTotal Dim ctCellMaster Dim testRowCountMat Dim alertStat Dim tempXLFile Dim xlApp As New Excel.Application 'ADDED FOR MEMORY Dim FileString As String 'ADDED FOR MEMORY xlApp.Application.Visible = True 'ADDED FOR MEMORY '################################################# ########################################### '########### READ IN MASTER FILE '################################################# ########################################### If fileNo = 1 Or IsEmpty(fileLocExcel) Then fileLocExcel = Get_File_Info(arrFiles(fileNo, colFileName), "Directory") End If FileString = arrFiles(fileNo, colFileName) 'ADDED FOR MEMORY xlApp.Workbooks.Open (FileString) 'Focus is now on the workbook 'ADDED FOR MEMORY Set Master = xlApp.ActiveWorkbook Set masterSht = xlApp.ActiveSheet MasterFile = Master.Name lastCellMaster = LastCellIn(masterSht) rowsMaster = LastRowIn(masterSht) arrFiles(fileNo, colFileRows) = rowsMaster colsMaster = LastColIn(masterSht) colsMaster = Mid(Cells(1, colsMaster).Address, 2, 1) If rowsMaster = Empty Or colsMaster = Empty Then 'File was not converted to Excel propertly arrFiles(fileNo, colFileStat) = "Empty File" Master.Close SaveChanges:=False errCount = errCount + 1 arrErrors(errCount, colKeyErrFile) = Get_File_Info(arrFiles(fileNo, colFileName), "FileName") ' 1 'KeyErr Anchor: Name arrErrors(errCount, colKeyErrCode) = "Empty Excel File" ' 2 'KeyErr Anchor: Anchor or Code arrErrors(errCount, colKeyErrDesc) = "Empty Excel File" ' 3 'KeyErr Anchor: Name arrErrors(errCount, colKeyErrStat) = "Empty Excel File" 'KeyErr Anchor: Special Function to perform (such as count repeats) Exit Sub End If ctCellMaster = 0 arrTemp = masterSht.Range("A1:" & colsMaster & rowsMaster).Value arrMaster = arrTemp Master.Close SaveChanges:=False 'Application.DisplayAlerts = alertStat Set masterSht = Nothing Set Master = Nothing xlApp.Quit Set xlApp = Nothing 'ADDED FOR MEMORY End Sub "Joel" wrote: 1) To speed up execution of your code and to stop blinking turn off screen updting at the beginning of the macro and then turn it back on at the end Application.ScreenUpdating = False Application.ScreenUpdating = True 2) Excel is sometime bad at comnpacting workbooks to reduce memory size. It may be best to create a new workbook with the your condensed table and savig the final results as a new file. This will probably cure youor memory problem. I suspect that maybe when you are creating the table you maybe copying formulas rather than just the values which may be the reason for the memory error. "MikeZz" wrote: Hi JP, I think I posted back to Joel when it should have gone to you. In case you are not notified of replies to him, please look at my 9/14 posts further down in the thread to answer all your previous questions. Thanks again, this thread is a lifesaver. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Reading current opened Excel book(file) into streams | Excel Programming | |||
Why Excel files opened from Explorer are slow - MVP response pleas | Excel Discussion (Misc queries) | |||
MY ARRAY FORMULA IS SLOW IF DATA LIST IS MORE THAN 10000R0WS | Excel Programming | |||
Reading from a excel sheet to an array | Excel Programming | |||
[excel 97 vba ] Reading ranges into an array | Excel Programming |