Ssignore08
New Member
- Joined
- Jul 8, 2015
- Messages
- 16
Pretty simple code. I have daily files (dy and mo) for multiple years (yr) for different areas (ucode) that are in .txt format. I want them in excel so that I can use them later for other vba macros.
So there are four "For" loops, then I declare the file name and the path name. When the file is opened, I use the wizard to delineate the values correctly. Then I was to save as an excel file and close the file.
There is a memory leak somewhere as the memory usage in the processes tab goes 5x within running 3 months of files. No extra files are open when I stop the code. The memory allocation does not immediately recover either. I had this problem before putting in cutcopymode and screenupdateing =false
bonus if you have a better way of running through all of the files other than my current system w/ the format(mo,00) I would appreciate that, but this is secondary I believe.
So there are four "For" loops, then I declare the file name and the path name. When the file is opened, I use the wizard to delineate the values correctly. Then I was to save as an excel file and close the file.
There is a memory leak somewhere as the memory usage in the processes tab goes 5x within running 3 months of files. No extra files are open when I stop the code. The memory allocation does not immediately recover either. I had this problem before putting in cutcopymode and screenupdateing =false
bonus if you have a better way of running through all of the files other than my current system w/ the format(mo,00) I would appreciate that, but this is secondary I believe.
Code:
Sub DailyData()
'
' Macro1 Macro
' open and extract files
'
'Dim mo As String
On Error GoTo Etrapper
Application.DisplayStatusBar = True
Application.ScreenUpdating = False
For i = 23 To 31
ucode = Cells(i, 1)
ucap = UCase(ucode)
For yr = 2000 To 2015
'Application.ScreenUpdating = True
Application.StatusBar = "Current iteration: " & i & "_" & yr
For mo = 1 To 12
For dy = 1 To 31
mo = Format(mo, "00")
dy = Format(dy, "00")
fname1 = yr & mo & dy & ucode
fname = yr & mo & dy & "." & ucode
Pathname = "C:\Users\sg8\Documents\data\_" & ucode & "_Daily_Data_Request\" & ucode & yr & "\"
'This is all one line of code that extracts everything
'it changes from fname to fnam based on if the folder name includes .osch or not... open both, one results in an error, the other works
' Workbooks.OpenText Filename:= _
' "C:\Users\sg8\Documents\TVA data lab\_" & ucode & "_schedules\" & ucap & "_" & yr & "\" & fname & "\" & fname _
Workbooks.OpenText Filename:= _
"C:\Users\sg8\Documents\TVA data lab\_" & ucode & "_Daily_Data_Request\" & ucode & yr & "\" & fname _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, TrailingMinusNumbers:=True
'make sure to save in excel format
Application.DisplayAlerts = False
Application.CutCopyMode = False
Set wkb = Workbooks(fname)
'Saving the Workbook
wkb.SaveAs Filename:=Pathname & fname1, FileFormat:=xlOpenXMLWorkbook
wkb.Close savechanges:=False
Set wkb = Nothing
Next dy
Next mo
Next yr
Next I
Etrapper:
Resume Next
End Sub
Last edited: