View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Simon Lloyd[_1331_] Simon Lloyd[_1331_] is offline
external usenet poster
 
Posts: 1
Default collect data automatically from a folder


This should do what you need:


VBA Code:
--------------------


Sub Main()
Dim F As String, i As Integer, n As Integer, wks As Worksheet
'Initialize
i = 1
Set wks = ActiveWorkbook.Worksheets.Add 'dummy worksheet to hold the file list
ActiveSheet.Name = "Index"
wks.Cells(i, 1).Value = F
'Get the first filename that matches the pattern
F = Dir("C:\*.xls", vbNormal)
Do While F < "" 'loop through all the files
'store the filename in a sheet
wks.Cells(i, 1).Value = F
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="C:\" & F, TextToDisplay:=F
ActiveCell.Offset(1, 0).Select
i = i + 1
F = Dir 'get the next filename
Loop
n = i - 1 'n is the number of files found
MsgBox "there were " & n & " Files Found"
'sort the list of files
Columns("A:A").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select

ActiveWorkbook.Save 'As Filename:=F

--------------------






aya2002;670935 Wrote:

Dear Friends,

I have just signed here, so I am very new here.

I need your help for my problem:

suppose that i have a folder contains more than 200 text files (.txt)
or may be other extension say .jpg, any way, I need a program to extract
the names of these files and list them into an Excel sheet and set a
hyperlink to these files, so that when i click any one in the Excel
sheet it will be opened automatically.

Thanks


--
Simon Lloyd

Regards,
Simon Lloyd
'Excel Chat' (http://www.thecodecage.com/forumz/chat.php)
------------------------------------------------------------------------
Simon Lloyd's Profile: 1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=187420

http://www.thecodecage.com/forumz/chat.php