[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Re: Paste filenames into cells

Don Guillett

12/14/2006 2:22:00 PM

try either of these

Sub GetFileList()
Dim iCtr As Integer

With Application.FileSearch
.NewSearch
.LookIn = "c:\aa"
.SearchSubFolders = True
.Filename = ".xls"
If .Execute > 0 Then
For iCtr = 1 To .FoundFiles.Count
Cells(iCtr, 1).Value = .FoundFiles(iCtr)
Next iCtr
End If
End With
End Sub
=====
or DIR

Sub anotherfindfiles()
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim MediaFileLocation As String
MediaFileLocation = "c:\yourfolder\*.xls"
FN = Dir(MediaFileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub


--
Don Guillett
SalesAid Software
dguillett1@austin.rr.com
"hmm" <hmm@discussions.microsoft.com> wrote in message
news:54E25246-B9B8-4018-8BB7-12F37A07946A@microsoft.com...
>I want the user of my worksheet to be able to select files from a single
> folder. Instead of opening them, Excel will paste the list of filenames,
> including the path, into a column of cells that I specify.
>
> How can I do it? Can it be done without a macro?
>
> Thanks.


1 Answer

HMM

12/14/2006 3:20:00 PM

0

Thanks Don.

I actually discovered a way to do it without using a macro! I simply go to
the command prompt, and use the "dir" command to get the list of files, copy
it, then paste into Excel. Until I learn more and feel comfortable using
macros, I prefer the added steps.

"Don Guillett" wrote:

> try either of these
>
> Sub GetFileList()
> Dim iCtr As Integer
>
> With Application.FileSearch
> .NewSearch
> .LookIn = "c:\aa"
> .SearchSubFolders = True
> .Filename = ".xls"
> If .Execute > 0 Then
> For iCtr = 1 To .FoundFiles.Count
> Cells(iCtr, 1).Value = .FoundFiles(iCtr)
> Next iCtr
> End If
> End With
> End Sub
> =====
> or DIR
>
> Sub anotherfindfiles()
> Application.ScreenUpdating = False
> Dim FN As String ' For File Name
> Dim ThisRow As Long
> Dim MediaFileLocation As String
> MediaFileLocation = "c:\yourfolder\*.xls"
> FN = Dir(MediaFileLocation)
> Do Until FN = ""
> ThisRow = ThisRow + 1
> Cells(ThisRow, 1) = FN
> FN = Dir
> Loop
> Application.ScreenUpdating = True
> End Sub
>
>
> --
> Don Guillett
> SalesAid Software
> dguillett1@austin.rr.com
> "hmm" <hmm@discussions.microsoft.com> wrote in message
> news:54E25246-B9B8-4018-8BB7-12F37A07946A@microsoft.com...
> >I want the user of my worksheet to be able to select files from a single
> > folder. Instead of opening them, Excel will paste the list of filenames,
> > including the path, into a column of cells that I specify.
> >
> > How can I do it? Can it be done without a macro?
> >
> > Thanks.
>
>
>