View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Files\folders in VBA

Left out a closing parenthesis

Sub Openfiles()
Dim sPath as String, sName as String
dim bk as workbook, sh as worksheet
dim rng as Range
sPath = "C:\Myfolder\"
sName = Dir(sPath & "*.xls")
do while sName < ""
set bk = workbooks.open(sPath & sName)
set sh = bk.worksheets(1)
set rng = sh.Range("A1")
bk.close SaveChanges:=False
sName = dir()
Loop
End Sub

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote:

The current folder for the current drive can be found with

CurDir

Sub Openfiles()
sPath = "C:\Myfolder\"
sName = Dir(sPath & "*.xls")
do while sName < ""
set bk = workbooks.open(sPath & sName
set sh = bk.worksheets(1)
set rng = sh.Range("A1")
bk.close SaveChanges:=False
sName = dir()
Loop
End Sub

--
Regards,
Tom Ogilvy

"funkymonkUK" wrote:


Hi

I want to create a sheet which shows the current main folder in a cell.
I know of getopenfilename in vba but there the user has to specify the
file as well where I just want the folder.

How do I get a list of Files which are in a specific folder? As I want
to create a list of them and then open them up, extract some data and
then close them.


--
funkymonkUK
------------------------------------------------------------------------
funkymonkUK's Profile: http://www.excelforum.com/member.php...o&userid=18135
View this thread: http://www.excelforum.com/showthread...hreadid=537997