Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default User selection of folder and open all .xls files within folder

I need to allow the user to select a folder so that .xls files meeting a
specific file naming convention can be opened. I know how to create an
array of workbooks based upon that naming convention, but I've not been
successful in allowing the user to select a folder. How should I code this?

Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default User selection of folder and open all .xls files within folder

Hi Barb,

'-----------------
I need to allow the user to select a folder so that .xls files meeting a
specific file naming convention can be opened. I know how to create an
array of workbooks based upon that naming convention, but I've not been
successful in allowing the user to select a folder. How should I code
this?
'-----------------

See John Walkenbach at:

Selecting a Directory
http://j-walk.com/ss/excel/tips/tip29.htm

See also Jim Rech's BrowseForFolder download which
may be freely downloaded from Stephen Bullen's
OfficeAutomation site:

http://www.bmsltd.ie/MVP/Default.htm

Also visit Chip Pearson at:

Selecting A Folder With VBA
http://www.cpearson.com/excel/BrowseFolder.htm



---
Regards,
Norman


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default User selection of folder and open all .xls files within folder

Here is one simple way


Sub LoopFolders()

Set oFSO = CreateObject("Scripting.FileSystemObject")

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

selectFiles .SelectedItems(1)

End With

Set oFSO = Nothing

End Sub


'---------------------------------------------------------------------------
Sub selectFiles(sPath)
'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set Folder = oFSO.GetFolder(sPath)

For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
End If
Next file

End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Barb Reinhardt" wrote in message
...
I need to allow the user to select a folder so that .xls files meeting a
specific file naming convention can be opened. I know how to create an
array of workbooks based upon that naming convention, but I've not been
successful in allowing the user to select a folder. How should I code
this?

Thanks,
Barb Reinhardt



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default User selection of folder and open all .xls files within folder

Just an addendum to Bob's reply:

Application.FileDialog was added in xl2002 (IIRC).

And I think Bob wanted to declare oFSO at the top of the module.


Bob Phillips wrote:

Here is one simple way

Sub LoopFolders()

Set oFSO = CreateObject("Scripting.FileSystemObject")

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

selectFiles .SelectedItems(1)

End With

Set oFSO = Nothing

End Sub

'---------------------------------------------------------------------------
Sub selectFiles(sPath)
'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set Folder = oFSO.GetFolder(sPath)

For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
End If
Next file

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Barb Reinhardt" wrote in message
...
I need to allow the user to select a folder so that .xls files meeting a
specific file naming convention can be opened. I know how to create an
array of workbooks based upon that naming convention, but I've not been
successful in allowing the user to select a folder. How should I code
this?

Thanks,
Barb Reinhardt


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default User selection of folder and open all .xls files within folder

I did indeed. my cut failed me.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Dave Peterson" wrote in message
...
Just an addendum to Bob's reply:

Application.FileDialog was added in xl2002 (IIRC).

And I think Bob wanted to declare oFSO at the top of the module.


Bob Phillips wrote:

Here is one simple way

Sub LoopFolders()

Set oFSO = CreateObject("Scripting.FileSystemObject")

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

selectFiles .SelectedItems(1)

End With

Set oFSO = Nothing

End Sub

'---------------------------------------------------------------------------
Sub selectFiles(sPath)
'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set Folder = oFSO.GetFolder(sPath)

For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
End If
Next file

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Barb Reinhardt" wrote in
message
...
I need to allow the user to select a folder so that .xls files meeting a
specific file naming convention can be opened. I know how to create
an
array of workbooks based upon that naming convention, but I've not been
successful in allowing the user to select a folder. How should I code
this?

Thanks,
Barb Reinhardt


--

Dave Peterson





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
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
How to List the names of the subfolders present in the folder (path of folder is given in the textbox by user ) divya Excel Programming 3 November 30th 06 11:34 AM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven[_2_] Excel Programming 1 January 24th 06 04:23 AM
Open all files in a folder Daniel Van Eygen Excel Programming 5 August 24th 04 04:48 PM


All times are GMT +1. The time now is 08:58 PM.

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"