Hi Guys,
First post so hello!
I have been googling and searching forums for a while and havent found a working solution to my problem.
After reading a few threads here I understand you get frustrated with posts just asking for help and not actually including enough detail to provide a sutable awnser so I will try to give as much detail as possible.
I have come across another thread here where there is code posted to read multiple text files in VBA and import specific data to an excel spreadsheet. I have managed to use this code to get the results I desire, however unfortunatly the files I need to extract are also in multiple folders (all under a specific subfolder however).
I'm using the following code..
This code will pull the data I require from the specified text file in \\gbdb1012\spparchive\SPP\110822\PRINT\
The folder stucture is as follows.
Root Folder
\\gbdb1012\spparchive\SPP\
Every Day a new folder is created in a YYMMDD format
\\gbdb1012\spparchive\SPP\110822\
Within this daily folder is another folder called print, in here is the file i need to pull data from
\\gbdb1012\spparchive\SPP\110822\PRINT
I need to be able to scan for text files in all the sub folders, i.e.
\\gbdb1012\spparchive\SPP\110821\PRINT
\\gbdb1012\spparchive\SPP\110822\PRINT
\\gbdb1012\spparchive\SPP\110823\PRINT
\\gbdb1012\spparchive\SPP\110824\PRINT
\\gbdb1012\spparchive\SPP\110825\PRINT
\\gbdb1012\spparchive\SPP\110826\PRINT
\\gbdb1012\spparchive\SPP\110827\PRINT
Obviously this is dynamic and ever changing so I imagine I will need some kind of loop to go though all the folders in the root folder one by one till it reaches the end?
Any suggestions on how I can alter the code to acomplish this?
Many thanks,
Please note this has been cross posted at...
http://www.ozgrid.com/forum/showthread.php?t=157461&p=572826#post572826
First post so hello!
I have been googling and searching forums for a while and havent found a working solution to my problem.
After reading a few threads here I understand you get frustrated with posts just asking for help and not actually including enough detail to provide a sutable awnser so I will try to give as much detail as possible.
I have come across another thread here where there is code posted to read multiple text files in VBA and import specific data to an excel spreadsheet. I have managed to use this code to get the results I desire, however unfortunatly the files I need to extract are also in multiple folders (all under a specific subfolder however).
I'm using the following code..
Code:
Sub read_text()
'Set wb = Workbooks.Add
workingflnm = ActiveWorkbook.Name
i = 5 'First row in Active Sheet
Set fd = CreateObject("Scripting.Filesystemobject")
pthnm = "[URL="file://gbdb1012/spparchive/SPP/110822/PRINT"]\\gbdb1012\spparchive\SPP\110822\PRINT[/URL]" 'Please change to your desired folder
Set fs = fd.GetFolder(pthnm)
For Each fl In fs.Files
If InStr(1, fl.Name, "eodlog.spp", vbTextCompare) > 0 Then
Set Txtobj = CreateObject("Scripting.filesystemobject")
Set Txtfl = Txtobj.getfile(fl)
Set Txtstrm = Txtfl.openastextstream(1, -2)
Do While Txtstrm.AtEndOfStream <> True
rdln = Txtstrm.readline
If InStr(1, rdln, "rfsruc", vbTextCompare) > 1 Then
x1 = InStr(1, rdln, "^", vbTextCompare)
x2 = InStr(1, rdln, "^GBVC110007^", vbTextCompare)
Workbooks(workingflnm).Sheets("Log File Extract").Cells(i, 1) = fl.Name
'Construction of Ohms String
strg = Mid(rdln, x1 + Len("^"), x2 + Len("") - (x1 + Len("^"))) 'The String picks the character Ohms in the Line as well
Workbooks(workingflnm).Sheets("Log File Extract").Cells(i, 2) = strg
i = i + 1
End If
Loop
End If
Next
End Sub
This code will pull the data I require from the specified text file in \\gbdb1012\spparchive\SPP\110822\PRINT\
The folder stucture is as follows.
Root Folder
\\gbdb1012\spparchive\SPP\
Every Day a new folder is created in a YYMMDD format
\\gbdb1012\spparchive\SPP\110822\
Within this daily folder is another folder called print, in here is the file i need to pull data from
\\gbdb1012\spparchive\SPP\110822\PRINT
I need to be able to scan for text files in all the sub folders, i.e.
\\gbdb1012\spparchive\SPP\110821\PRINT
\\gbdb1012\spparchive\SPP\110822\PRINT
\\gbdb1012\spparchive\SPP\110823\PRINT
\\gbdb1012\spparchive\SPP\110824\PRINT
\\gbdb1012\spparchive\SPP\110825\PRINT
\\gbdb1012\spparchive\SPP\110826\PRINT
\\gbdb1012\spparchive\SPP\110827\PRINT
Obviously this is dynamic and ever changing so I imagine I will need some kind of loop to go though all the folders in the root folder one by one till it reaches the end?
Any suggestions on how I can alter the code to acomplish this?
Many thanks,
Please note this has been cross posted at...
http://www.ozgrid.com/forum/showthread.php?t=157461&p=572826#post572826