Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Any way to grab a .csv file from a folder using Wildcards

Does anyone know of a way that I can grab a .csv file out of a local
folder with out specifying the exact document. I have created a macro
that can take the CSV data and import into the Excel worksheet save it
and print it but only if I code it to that exact CSV document. I was
hoping to be able to just have it grab any CSV document in a
particular folder. There will be only one CSV document at anytime in
the folder but it will not always be named the same. Any ideas.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Any way to grab a .csv file from a folder using Wildcards

David,

You can use
inFile = Application.GetOpenFilename
which will open a standard "Open" file dialog box to browse for your .csv
file and returns a file name and path
ie (inFile = "C:\My Documents\MyCSV.csv")

Dan E

"David Johnston" wrote in message
om...
Does anyone know of a way that I can grab a .csv file out of a local
folder with out specifying the exact document. I have created a macro
that can take the CSV data and import into the Excel worksheet save it
and print it but only if I code it to that exact CSV document. I was
hoping to be able to just have it grab any CSV document in a
particular folder. There will be only one CSV document at anytime in
the folder but it will not always be named the same. Any ideas.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Any way to grab a .csv file from a folder using Wildcards

Here's another option,

This one has a fixed folder to look for the csv file in

Private Sub CommandButton1_Click()
On Error GoTo Endit
Dim fs, f, f1, fc, s
folderspec = "C:\My Documents"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
i = 0
For Each f1 In fc
If Right(f1.Name, 3) = "csv" Then
inFileName = f1.ParentFolder.Path & "\" & f1.Name
i = i + 1
End If
Next
ret = MsgBox(i & " CSV file(s) found ," & inFileName & " used",
vbOKOnly)

Endit:
If i = 0 Then
ret = MsgBox("No CSV file Found", vbOKOnly, "Bad Input")
End If
End Sub

Dan E

"David Johnston" wrote in message
om...
Does anyone know of a way that I can grab a .csv file out of a local
folder with out specifying the exact document. I have created a macro
that can take the CSV data and import into the Excel worksheet save it
and print it but only if I code it to that exact CSV document. I was
hoping to be able to just have it grab any CSV document in a
particular folder. There will be only one CSV document at anytime in
the folder but it will not always be named the same. Any ideas.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Any way to grab a .csv file from a folder using Wildcards

if there is only one csv file in the directory, try the following

f=dir("c:\my folder\*.csv")

at this point f will be the filename including the path,

Lynn S
"David Johnston" wrote in message
om...
Does anyone know of a way that I can grab a .csv file out of a local
folder with out specifying the exact document. I have created a macro
that can take the CSV data and import into the Excel worksheet save it
and print it but only if I code it to that exact CSV document. I was
hoping to be able to just have it grab any CSV document in a
particular folder. There will be only one CSV document at anytime in
the folder but it will not always be named the same. Any ideas.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
opening file from ftp folder PBISMaryland Excel Discussion (Misc queries) 1 September 16th 09 11:37 AM
in which folder can you save a .CSV file? chivagirl Excel Discussion (Misc queries) 17 December 31st 07 10:44 PM
Create formula to grab file path Sonnie Excel Discussion (Misc queries) 0 August 16th 06 06:48 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
file folder macro's shrek Links and Linking in Excel 3 September 16th 05 10:17 PM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"