ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   import only files with a certain extension (https://www.excelbanter.com/excel-programming/380405-import-only-files-certain-extension.html)

kmcosta

import only files with a certain extension
 
I need help trying to import only files with a given extension. I dont
need to consider the text string that comes before the extension. For
example: I have a file named 1GC18950.057, but I only want to look at
the .057 for this file in a known folder. How do I change the code
below to only look for the extension and not the text string before it.
Any help will be GREATLY appreciated!!

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and
Settings\Kevin\Desktop\data\1GC18950.057",


NickHK

import only files with a certain extension
 
You have to provide a full file name in the connection string, so you need
some way to determine that before. One way :

Dim Filename as string
Const DirSearch as string="C:\Documents and Settings\Kevin\Desktop\data\"

filename=dir(DirSearch & "*.057")
if filename<"" then
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & DirSearch & filename,..etc

Else
msgbox "No .057 files"
end if

Or look into Application.GetOpenFilename for more flexibility.

NickHK

"kmcosta" wrote in message
ups.com...
I need help trying to import only files with a given extension. I dont
need to consider the text string that comes before the extension. For
example: I have a file named 1GC18950.057, but I only want to look at
the .057 for this file in a known folder. How do I change the code
below to only look for the extension and not the text string before it.
Any help will be GREATLY appreciated!!

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and
Settings\Kevin\Desktop\data\1GC18950.057",





All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com