Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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
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
.TMP files are corrupting my folders Ed Excel Discussion (Misc queries) 2 February 8th 08 02:08 PM
Files and Folders check JohnUK Excel Programming 6 December 7th 05 04:18 PM
links to same files in different folders Henk Excel Worksheet Functions 2 August 19th 05 02:48 AM
Opening Files/Folders animalfriend7 Excel Discussion (Misc queries) 2 June 23rd 05 11:57 PM
Drive - Folders - Files DPC Excel Discussion (Misc queries) 1 May 26th 05 08:39 PM


All times are GMT +1. The time now is 04:12 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"