ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting a Folder or Subfolder (https://www.excelbanter.com/excel-programming/376980-selecting-folder-subfolder.html)

Rabi

Selecting a Folder or Subfolder
 
Hi everyone from a new comer

My application extracts filenames from folders or subfolders. Sometimes, the
folders are deep down making it cumbersome as well as error-prone, for my
colleagues (users of this application), to type the long path in a textbox.

I need to include a code which helps the users select a folder or a
subfolder from a dialogbox; like the FileOpen dialogbox. The FileOpen has a
restriction of choosing particular file(s). Although, I can truncate the
returned string from this dialogobx to extract the path - but I don't want
this method to use for some reasons.

I expect the members of the forum suggest me more professional way to solve
this problem.

Regards,

Rabi

Rabi

Selecting a Folder or Subfolder - more clearly described
 
I am afraid, I did not describe my query clearly. I tried to describe it more
clearly, below:

I want to read a folder name on the disk (in order to extract all the files
under this folder and its subfolders). Presently, my application requires to
type the path, in a textbox, as below, for example:

"d:\documents\projects\reports\cities\"

I want a way to choose a folder, like the above , for example, by clicking
from the list of folders instead of typing the path (sometimes much longer
than the above example). Consequently, my applications extracts all the files
under this folder and its subfolders.

Please note that I need to read the FolderName only, not the FileName(s).

Regards,

Rabi


NickHK

Selecting a Folder or Subfolder
 
Use the Windows API SHBrowseForFolder etc :

http://vbnet.mvps.org/code/browse/browsefolders.htm

NickHK

"Rabi" wrote in message
...
Hi everyone from a new comer

My application extracts filenames from folders or subfolders. Sometimes,

the
folders are deep down making it cumbersome as well as error-prone, for my
colleagues (users of this application), to type the long path in a

textbox.

I need to include a code which helps the users select a folder or a
subfolder from a dialogbox; like the FileOpen dialogbox. The FileOpen has

a
restriction of choosing particular file(s). Although, I can truncate the
returned string from this dialogobx to extract the path - but I don't want
this method to use for some reasons.

I expect the members of the forum suggest me more professional way to

solve
this problem.

Regards,

Rabi




Rabi

Selecting a Folder or Subfolder
 
Thanks NickHK for the response. I am afraid it is not "VBA for Excel"
complaint code.
On pasting the code, API declaration statements are not identified by the VBE.

Is there something more to have this code run.

Regards,

Rabi

"NickHK" wrote:

Use the Windows API SHBrowseForFolder etc :

http://vbnet.mvps.org/code/browse/browsefolders.htm

NickHK

"Rabi" wrote in message
...
Hi everyone from a new comer

My application extracts filenames from folders or subfolders. Sometimes,

the
folders are deep down making it cumbersome as well as error-prone, for my
colleagues (users of this application), to type the long path in a

textbox.

I need to include a code which helps the users select a folder or a
subfolder from a dialogbox; like the FileOpen dialogbox. The FileOpen has

a
restriction of choosing particular file(s). Although, I can truncate the
returned string from this dialogobx to extract the path - but I don't want
this method to use for some reasons.

I expect the members of the forum suggest me more professional way to

solve
this problem.

Regards,

Rabi





NickHK

Selecting a Folder or Subfolder
 
As the comment says :
"hwnd of the window that receives messages from the call. Can be your
application or the handle from GetDesktopWindow()"
So use
.hOwner = GetDesktopWindow()
and add the declaration with the other Declare statements
Private Declare Function GetDesktopWindow Lib "user32" Alias
"GetDesktopWindow" () As Long

The only other difference maybe that you need a destination for the output
instead a "Label1".

NickHK

"Rabi" wrote in message
...
Thanks NickHK for the response. I am afraid it is not "VBA for Excel"
complaint code.
On pasting the code, API declaration statements are not identified by the

VBE.

Is there something more to have this code run.

Regards,

Rabi

"NickHK" wrote:

Use the Windows API SHBrowseForFolder etc :

http://vbnet.mvps.org/code/browse/browsefolders.htm

NickHK

"Rabi" wrote in message
...
Hi everyone from a new comer

My application extracts filenames from folders or subfolders.

Sometimes,
the
folders are deep down making it cumbersome as well as error-prone, for

my
colleagues (users of this application), to type the long path in a

textbox.

I need to include a code which helps the users select a folder or a
subfolder from a dialogbox; like the FileOpen dialogbox. The FileOpen

has
a
restriction of choosing particular file(s). Although, I can truncate

the
returned string from this dialogobx to extract the path - but I don't

want
this method to use for some reasons.

I expect the members of the forum suggest me more professional way to

solve
this problem.

Regards,

Rabi







Rabi

Selecting a Folder or Subfolder
 
Now, I got the point. Thank you very much NickHK.

Best regards,

Rabi

"NickHK" wrote:

As the comment says :
"hwnd of the window that receives messages from the call. Can be your
application or the handle from GetDesktopWindow()"
So use
.hOwner = GetDesktopWindow()
and add the declaration with the other Declare statements
Private Declare Function GetDesktopWindow Lib "user32" Alias
"GetDesktopWindow" () As Long

The only other difference maybe that you need a destination for the output
instead a "Label1".

NickHK

"Rabi" wrote in message
...
Thanks NickHK for the response. I am afraid it is not "VBA for Excel"
complaint code.
On pasting the code, API declaration statements are not identified by the

VBE.

Is there something more to have this code run.

Regards,

Rabi

"NickHK" wrote:

Use the Windows API SHBrowseForFolder etc :

http://vbnet.mvps.org/code/browse/browsefolders.htm

NickHK

"Rabi" wrote in message
...
Hi everyone from a new comer

My application extracts filenames from folders or subfolders.

Sometimes,
the
folders are deep down making it cumbersome as well as error-prone, for

my
colleagues (users of this application), to type the long path in a
textbox.

I need to include a code which helps the users select a folder or a
subfolder from a dialogbox; like the FileOpen dialogbox. The FileOpen

has
a
restriction of choosing particular file(s). Although, I can truncate

the
returned string from this dialogobx to extract the path - but I don't

want
this method to use for some reasons.

I expect the members of the forum suggest me more professional way to
solve
this problem.

Regards,

Rabi








All times are GMT +1. The time now is 01:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com