Hello everyone... been some time since I last posted in this forum... Hope everyone is doing well...
I have a question:
I have a bit of code that will allow me to "point" to a folder where I have placed some .dat files to be processed and process each of the files until all have been done. Now I have a situation where I have a folder of files where some of the data I'm processing is fragmented into separate files. Each file name is similar except for the extension at the end of each file name "ie: filename_1, filename_2, etc). What I'm trying to do is IF there are separate files for a given file name, I want to combine the data into one file or onto one tab in the workbook my code is running from. Any suggestions as to how I might achieve this ?
Thanks !
Loco
With Application.FileDialog(msoFileDialogFolderPicker) ' open file dialog box and select the folder that contains the .dat files.
.InitialFileName = Application.DefaultFilePath & "C:\Users"
.Title = "Please select the folder where the *.DAT data Files are located:"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & ""
End If
End With
p = xDirect$ & "/*.dat" ' This will ONLY open the .dat files, can be modified for other file formats
x = GetFileList(p)
For k = LBound(x) To UBound(x) ' all of the files in the folder
sFileName = xDirect$ & x(k)
If sFileName = "False" Then Exit Sub ' Exits if there are no files in the folder
Workbooks.OpenText FileName:=sFileName _
, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _
False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1) _
, TrailingMinusNumbers:=True
Set WBDat = ActiveWorkbook 'Sets the active workbook equal to WBDat or WorkBook - data file
' MsgBox "active workbook" & WBDat
If WBDat Is Nothing Then
MsgBox ".DAT data file not open"
Exit Sub
Else
End If
file_name = sFileName
strFileFullName = ActiveWorkbook.FullName
I have a question:
I have a bit of code that will allow me to "point" to a folder where I have placed some .dat files to be processed and process each of the files until all have been done. Now I have a situation where I have a folder of files where some of the data I'm processing is fragmented into separate files. Each file name is similar except for the extension at the end of each file name "ie: filename_1, filename_2, etc). What I'm trying to do is IF there are separate files for a given file name, I want to combine the data into one file or onto one tab in the workbook my code is running from. Any suggestions as to how I might achieve this ?
Thanks !
Loco
With Application.FileDialog(msoFileDialogFolderPicker) ' open file dialog box and select the folder that contains the .dat files.
.InitialFileName = Application.DefaultFilePath & "C:\Users"
.Title = "Please select the folder where the *.DAT data Files are located:"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & ""
End If
End With
p = xDirect$ & "/*.dat" ' This will ONLY open the .dat files, can be modified for other file formats
x = GetFileList(p)
For k = LBound(x) To UBound(x) ' all of the files in the folder
sFileName = xDirect$ & x(k)
If sFileName = "False" Then Exit Sub ' Exits if there are no files in the folder
Workbooks.OpenText FileName:=sFileName _
, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _
False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1) _
, TrailingMinusNumbers:=True
Set WBDat = ActiveWorkbook 'Sets the active workbook equal to WBDat or WorkBook - data file
' MsgBox "active workbook" & WBDat
If WBDat Is Nothing Then
MsgBox ".DAT data file not open"
Exit Sub
Else
End If
file_name = sFileName
strFileFullName = ActiveWorkbook.FullName