muirfield59
New Member
- Joined
- Sep 20, 2017
- Messages
- 2
Hi all,
I am importing .rpt files into excel using a vba code that I've attached at the bottom. Currently, I select a folder to import, and it imports all the files within that folder. I need to be able to check if I have imported a file before, and not import it again. The file names are a bunch of dates (04032017, 04042017, etc.). Any suggestions?
I am importing .rpt files into excel using a vba code that I've attached at the bottom. Currently, I select a folder to import, and it imports all the files within that folder. I need to be able to check if I have imported a file before, and not import it again. The file names are a bunch of dates (04032017, 04042017, etc.). Any suggestions?
Code:
Dim xStrPath As String
Dim xFileDialog As FileDialog
Dim xFile As String
Dim xCount As Long
Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
xFileDialog.AllowMultiSelect = False
xFileDialog.Title = "Select a folder"
If xFileDialog.Show = -1 Then
xStrPath = xFileDialog.SelectedItems(1)
End If
If xStrPath = "" Then Exit Sub
Application.ScreenUpdating = False
xFile = Dir(xStrPath & "\*.rpt")
Do While xFile <> ""
xCount = xCount + 1
Sheets(xCount).Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
& xStrPath & "" & xFile, Destination:=Range("A1"))
.Name = "a" & xCount
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 2, 2, 2, 2, 2, 2)
.TextFileFixedColumnWidths = Array(3, 12, 4, 14, 12, 81)
.TextFileTrailingMinusNumbers = False
.Refresh BackgroundQuery:=False
xFile = Dir
End With
Loop
Last edited by a moderator: