Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Files\folders in VBA
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Files\folders in VBA
sorry coudl you give me an example of this application.filesearch? I cant seem to get it to work. -- funkymonkUK ------------------------------------------------------------------------ funkymonkUK's Profile: http://www.excelforum.com/member.php...o&userid=18135 View this thread: http://www.excelforum.com/showthread...hreadid=537997 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Files\folders in VBA
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Files\folders in VBA
Filesearch has been claimed to be unreliable although I personally haven't
had any problems. the help example is pretty compreshensive: With Application.FileSearch .NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = ".txt" .MatchTextExactly = True .FileType = msoFileTypeAllFiles If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count MsgBox .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With -- regards, Tom Ogilvy "funkymonkUK" wrote: sorry coudl you give me an example of this application.filesearch? I cant seem to get it to work. -- funkymonkUK ------------------------------------------------------------------------ funkymonkUK's Profile: http://www.excelforum.com/member.php...o&userid=18135 View this thread: http://www.excelforum.com/showthread...hreadid=537997 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Files\folders in VBA
Dim FSO As Object
Sub ProcessFiles() Dim i As Long Dim sFolder As String Dim fldr As Object Dim Folder As Object Dim file As Object Dim Files As Object Dim this As Workbook Set FSO = CreateObject("Scripting.FileSystemObject") Set this = ActiveWorkbook sFolder = "C:\MyTest" Set Folder = FSO.GetFolder(sFolder) Set Files = Folder.Files For Each file In Files If file.Type = "Microsoft Excel Worksheet" Then Workbooks.Open Filename:=file.Path With ActiveWorkbook 'do something with the workbook .Close End With End If Next file End Sub -- HTH Bob Phillips (remove nothere from email address if mailing direct) "funkymonkUK" wrote in message ... 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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Files\folders in VBA
I have a few examples here
http://www.rondebruin.nl/copy3.htm -- Regards Ron de Bruin http://www.rondebruin.nl "funkymonkUK" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
.TMP files are corrupting my folders | Excel Discussion (Misc queries) | |||
Files and Folders check | Excel Programming | |||
links to same files in different folders | Excel Worksheet Functions | |||
Opening Files/Folders | Excel Discussion (Misc queries) | |||
Drive - Folders - Files | Excel Discussion (Misc queries) |