Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Dynamic folder??

Here is a little function that returns the selected folder


Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long


Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long


Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-----------------------------*------------------------------*--
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-----------------------------*------------------------------*--
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long


bInfo.pidlRoot = 0& 'Root folder = Desktop


bInfo.lpszTitle = Name


bInfo.ulFlags = &H1 'Type of directory to Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog


'Parse the result
path = Space$(512)


GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If


End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"broogle" wrote in message
oups.com...
This code below will count the total of files in c:\myfiles\
Is there a way to change the folder as dynamic, so user is free to
chose the folder she/he wants.
What I want is, when the code is running the pop up box will be shown
and user can browser to find the folder and when OK button is pressed
the code will count the files in that folde.
Thank and appreciate your help.

Private Sub countfiles()

Set fs = Application.FileSearch
With fs
.LookIn = "C:\Myfiles\"
.SearchSubFolders = False
.Filename = "*.xls"
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
Range("A" & i) = .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

End Sub



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 can i change my default working folder to a networked folder? wizard1154 Excel Discussion (Misc queries) 4 April 18th 07 07:29 PM
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? Subteam Excel Discussion (Misc queries) 2 May 7th 06 08:14 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
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


All times are GMT +1. The time now is 12:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"