Get all XLSx or CSV (1 Viewer)

Joaofigu

Registered User.
Local time
Today, 11:12
Joined
Apr 12, 2019
Messages
12
I need button to seach in folders if there is a XLSX or CSV file and import to a table, i were trying this code for each folder.

Sub Import_files2me()

Const strPath As String = "C:\COCFAT\99_input\CDT" 'Directory Path 1
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number

'Loop through the folder & build file list
strFile = Dir(strPath & "*.xlsx")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then

MsgBox "Não existem ficheiros na pasta CDT"
If MsgBox("Quer continuar?", vbYesNo + vbQuestion) = vbYes Then
Else
Exit Sub
End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:12
Joined
Oct 29, 2018
Messages
21,453
Hi. I didn't see what was your question. Also, wouldn't it be dangerous to grab any file and just import it? Also, if the files are different in structure, that could pose some problems too. Can you please explain exactly what you're trying to accomplish to maybe help clarify what you're asking? Thanks.
 

Joaofigu

Registered User.
Local time
Today, 11:12
Joined
Apr 12, 2019
Messages
12
Sorry about my english,
I´ve a rotine to import all files in folders, it could be CSV or XLSX but always with the same structer file and layout.

After import it i want to move the files to another folder adding date and time.

thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:12
Joined
Oct 29, 2018
Messages
21,453
Sorry about my english,
I´ve a rotine to import all files in folders, it could be CSV or XLSX but always with the same structer file and layout.

After import it i want to move the files to another folder adding date and time.

thanks.
Are you referring to the "routine" you posted earlier? If so, is there anything wrong with it? In other words, what exactly are you asking of us?
 

Joaofigu

Registered User.
Local time
Today, 11:12
Joined
Apr 12, 2019
Messages
12
my code is getting error in Const strPath As String ,
get u help me?
thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:12
Joined
Oct 29, 2018
Messages
21,453
my code is getting error in Const strPath As String ,
get u help me?
thanks.
Okay, just a guess but try moving that line to the very top of your module. For example, instead of this:
Code:
Sub Import_files2me()

Const strPath As String = "C:\COCFAT\99_input\CDT"  'Directory Path 1
...
Try it this way:
Code:
Const strPath As String = "C:\COCFAT\99_input\CDT"  'Directory Path 1

Sub Import_files2me()
...
Hope that helps...
 

Users who are viewing this thread

Top Bottom